]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
i2c: Unregister dummy devices last on adapter removal
authorJean Delvare <khali@linux-fr.org>
Fri, 14 Jan 2011 21:03:49 +0000 (22:03 +0100)
committerPaul Gortmaker <paul.gortmaker@windriver.com>
Sun, 26 Jun 2011 16:46:30 +0000 (12:46 -0400)
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: Paul Gortmaker <paul.gortmaker@windriver.com>
drivers/i2c/i2c-core.c

index c2258a51fe0ce3bb09055220c645602ab467c876..b67109cc1ce9663af039827c0ca1244824a5e834 100644 (file)
@@ -835,6 +835,14 @@ static int i2c_do_del_adapter(struct i2c_driver *driver,
 }
 
 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)
@@ -891,8 +899,12 @@ int i2c_del_adapter(struct i2c_adapter *adap)
        i2c_unlock_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,