i2c_set/get_clientdata inconsistencies
Hi David, Mark,
I noticed that a few Linux i2c chip drivers do not use i2c_set_clientdata and i2c_get_clientdata in a consistent manner.
The isp1301_omap and tps65010 drivers do call i2c_set_clientdata at client registration time, but then never call i2c_get_clientdata, not even at release time, instead using container_of directly.
The m41t00 chip driver does not have private data, so it doesn't call i2c_set_clientdata, but nevertheless uses i2c_get_clientdata at release time. This can't be correct.
Here are my proposed fixes. I'm quite confident I am right for the m41t00 driver, not quite so for the other two, and I can't test any of them anyway, so please review and comment.
Thanks.
drivers/i2c/chips/isp1301_omap.c | 4 ++-- drivers/i2c/chips/m41t00.c | 2 +- drivers/i2c/chips/tps65010.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-)
drivers/i2c/chips/isp1301_omap.c +2 -2
@@ -1197,7 +1197,7 @@ {struct isp1301 *isp; - isp = container_of(dev, struct isp1301, client.dev); + isp =i2c_get_clientdata (to_i2c_client (dev));/* ugly -- i2c hijacks our memory hook to wait_for_completion() */ if (isp->i2c_release)
@@ -1211,7 +1211,7 @@ {struct isp1301 *isp; - isp = container_of(i2c, struct isp1301, client); + isp =i2c_get_clientdata (i2c);isp1301_clear_bits (isp,ISP1301_INTERRUPT_FALLING , ~0 );isp1301_clear_bits (isp,ISP1301_INTERRUPT_RISING , ~0 );
drivers/i2c/chips/m41t00.c +1 -1
@@ -207,7 +207,7 @@int rc;if ((rc =i2c_detach_client (client)) =0 ) { -kfree (i2c_get_clientdata (client)); +kfree (client);tasklet_kill (&m41t00_tasklet); }return rc;
drivers/i2c/chips/tps65010.c +1 -1
@@ -465,7 +465,7 @@ {struct tps65010 *tps; - tps = container_of(client, struct tps65010, client); + tps =i2c_get_clientdata (client);#ifdef CONFIG_ARM if (machine_is_omap_h2 ())omap_free_gpio (58 );
Signature · 1 line
Jean Delvare
Quoted 7 lines · Jean Delvare
I noticed that a few Linux i2c chip drivers do not use
i2c_set_clientdataandi2c_get_clientdatain a consistent manner.The
isp1301_omapand tps65010 drivers do calli2c_set_clientdataat client registration time, but then never calli2c_get_clientdata, not even at release time, instead usingcontainer_ofdirectly.
I don't see a problem. They allocated the memory and know how it's laid out; why shouldn't they use container_of()? A subtraction being cheaper than a memory access, and all that. Though it's true that if they don't get_clientdata, they might as well not set_clientdata.
- Dave