diff options
author | Wolfram Sang <w.sang@pengutronix.de> | 2010-05-04 05:09:27 -0400 |
---|---|---|
committer | Jean Delvare <khali@linux-fr.org> | 2010-05-04 05:09:27 -0400 |
commit | e4a7b9b04de15f6b63da5ccdd373ffa3057a3681 (patch) | |
tree | 7f2f49df9dc66b334b85f83347df03d2b0d0a721 | |
parent | d93ac51c7a129db7a1431d859a3ef45a0b1f3fc5 (diff) |
i2c-core: Erase pointer to clientdata on removal
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>
-rw-r--r-- | Documentation/i2c/writing-clients | 5 | ||||
-rw-r--r-- | drivers/i2c/i2c-core.c | 8 |
2 files changed, 11 insertions, 2 deletions
diff --git a/Documentation/i2c/writing-clients b/Documentation/i2c/writing-clients index 3219ee0dbfef..5ebf5af1d716 100644 --- a/Documentation/i2c/writing-clients +++ b/Documentation/i2c/writing-clients | |||
@@ -74,6 +74,11 @@ structure at all. You should use this to keep device-specific data. | |||
74 | /* retrieve the value */ | 74 | /* retrieve the value */ |
75 | void *i2c_get_clientdata(const struct i2c_client *client); | 75 | void *i2c_get_clientdata(const struct i2c_client *client); |
76 | 76 | ||
77 | Note that starting with kernel 2.6.34, you don't have to set the `data' field | ||
78 | to NULL in remove() or if probe() failed anymore. The i2c-core does this | ||
79 | automatically on these occasions. Those are also the only times the core will | ||
80 | touch this field. | ||
81 | |||
77 | 82 | ||
78 | Accessing the client | 83 | Accessing the client |
79 | ==================== | 84 | ==================== |
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c index 3202a86f420e..b9306b1a6baa 100644 --- a/drivers/i2c/i2c-core.c +++ b/drivers/i2c/i2c-core.c | |||
@@ -117,8 +117,10 @@ static int i2c_device_probe(struct device *dev) | |||
117 | dev_dbg(dev, "probe\n"); | 117 | dev_dbg(dev, "probe\n"); |
118 | 118 | ||
119 | status = driver->probe(client, i2c_match_id(driver->id_table, client)); | 119 | status = driver->probe(client, i2c_match_id(driver->id_table, client)); |
120 | if (status) | 120 | if (status) { |
121 | client->driver = NULL; | 121 | client->driver = NULL; |
122 | i2c_set_clientdata(client, NULL); | ||
123 | } | ||
122 | return status; | 124 | return status; |
123 | } | 125 | } |
124 | 126 | ||
@@ -139,8 +141,10 @@ static int i2c_device_remove(struct device *dev) | |||
139 | dev->driver = NULL; | 141 | dev->driver = NULL; |
140 | status = 0; | 142 | status = 0; |
141 | } | 143 | } |
142 | if (status == 0) | 144 | if (status == 0) { |
143 | client->driver = NULL; | 145 | client->driver = NULL; |
146 | i2c_set_clientdata(client, NULL); | ||
147 | } | ||
144 | return status; | 148 | return status; |
145 | } | 149 | } |
146 | 150 | ||