diff options
author | Jean Delvare <khali@linux-fr.org> | 2011-01-14 22:03:49 +0100 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2011-02-17 15:37:03 -0800 |
commit | c514f424190f82233365de5293cecc5cbb23ed9c (patch) | |
tree | 45dc74aa78385db6fd3bcb2be50aa67dd2881e85 | |
parent | 524d108836b3f33e143f539c947475be8d43a655 (diff) | |
download | lwn-c514f424190f82233365de5293cecc5cbb23ed9c.tar.gz lwn-c514f424190f82233365de5293cecc5cbb23ed9c.zip |
i2c: Unregister dummy devices last on adapter removal
commit 5219bf884b6e2b54e734ca1799b6f0014bb2b4b7 upstream.
Remove real devices first and dummy devices last. This gives device
driver which instantiated dummy devices themselves a chance to clean
them up before we do.
Signed-off-by: Jean Delvare <khali@linux-fr.org>
Tested-by: Hans Verkuil <hverkuil@xs4all.nl>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
-rw-r--r-- | drivers/i2c/i2c-core.c | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c index 8066db706e6c..71a5f89993c1 100644 --- a/drivers/i2c/i2c-core.c +++ b/drivers/i2c/i2c-core.c @@ -745,6 +745,14 @@ static int i2c_do_del_adapter(struct device_driver *d, void *data) static int __unregister_client(struct device *dev, void *dummy) { struct i2c_client *client = i2c_verify_client(dev); + if (client && strcmp(client->name, "dummy")) + i2c_unregister_device(client); + return 0; +} + +static int __unregister_dummy(struct device *dev, void *dummy) +{ + struct i2c_client *client = i2c_verify_client(dev); if (client) i2c_unregister_device(client); return 0; @@ -793,8 +801,12 @@ int i2c_del_adapter(struct i2c_adapter *adap) } /* Detach any active clients. This can't fail, thus we do not - checking the returned value. */ + * check the returned value. This is a two-pass process, because + * we can't remove the dummy devices during the first pass: they + * could have been instantiated by real devices wishing to clean + * them up properly, so we give them a chance to do that first. */ res = device_for_each_child(&adap->dev, NULL, __unregister_client); + res = device_for_each_child(&adap->dev, NULL, __unregister_dummy); #ifdef CONFIG_I2C_COMPAT class_compat_remove_link(i2c_adapter_compat_class, &adap->dev, |