]> bbs.cooldavid.org Git - net-next-2.6.git/commitdiff
i2c-core: Erase pointer to clientdata on removal
authorWolfram Sang <w.sang@pengutronix.de>
Tue, 4 May 2010 09:09:27 +0000 (11:09 +0200)
committerJean Delvare <khali@linux-fr.org>
Tue, 4 May 2010 09:09:27 +0000 (11:09 +0200)
After discovering that a lot of i2c-drivers leave the pointer to their
clientdata dangling, it was decided to let the core handle this issue.
It is assumed that the core may access the private data after remove()
as there are no guarantees for the lifetime of such pointers anyhow (see
thread starting at http://lkml.org/lkml/2010/3/21/68)

Signed-off-by: Wolfram Sang <w.sang@pengutronix.de>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
Documentation/i2c/writing-clients
drivers/i2c/i2c-core.c

index 3219ee0dbfef1eab9493253d6307acd7bb282019..5ebf5af1d71606ae3d6d31557f97ce7f3077add7 100644 (file)
@@ -74,6 +74,11 @@ structure at all.  You should use this to keep device-specific data.
        /* retrieve the value */
        void *i2c_get_clientdata(const struct i2c_client *client);
 
+Note that starting with kernel 2.6.34, you don't have to set the `data' field
+to NULL in remove() or if probe() failed anymore. The i2c-core does this
+automatically on these occasions. Those are also the only times the core will
+touch this field.
+
 
 Accessing the client
 ====================
index 3202a86f420e9e5b6dac41aefcefd409b3a72ed2..b9306b1a6baa0e0f30d5777e3eb5782020aa0560 100644 (file)
@@ -117,8 +117,10 @@ static int i2c_device_probe(struct device *dev)
        dev_dbg(dev, "probe\n");
 
        status = driver->probe(client, i2c_match_id(driver->id_table, client));
-       if (status)
+       if (status) {
                client->driver = NULL;
+               i2c_set_clientdata(client, NULL);
+       }
        return status;
 }
 
@@ -139,8 +141,10 @@ static int i2c_device_remove(struct device *dev)
                dev->driver = NULL;
                status = 0;
        }
-       if (status == 0)
+       if (status == 0) {
                client->driver = NULL;
+               i2c_set_clientdata(client, NULL);
+       }
        return status;
 }