diff mbox

i2c: mux: Remove unneeded platform_set_drvdata to NULL in remove

Message ID 1360953682-25066-1-git-send-email-dianders@chromium.org
State Rejected
Headers show

Commit Message

Doug Anderson Feb. 15, 2013, 6:41 p.m. UTC
Stephen Warren pointed out as part of a code review of another mux
driver that there should be no need to have
"platform_set_drvdata(pdev, NULL)" in the remove function.  Get rid of
it in the i2c-mux-gpio driver.

See Stephen's comment at:
  http://www.gossamer-threads.com/lists/linux/kernel/1678627?do=post_view_threaded#1678627

Signed-off-by: Doug Anderson <dianders@chromium.org>
---
 drivers/i2c/muxes/i2c-mux-gpio.c | 1 -
 1 file changed, 1 deletion(-)

Comments

Wolfram Sang Feb. 15, 2013, 7:37 p.m. UTC | #1
On Fri, Feb 15, 2013 at 10:41:22AM -0800, Doug Anderson wrote:
> Stephen Warren pointed out as part of a code review of another mux
> driver that there should be no need to have
> "platform_set_drvdata(pdev, NULL)" in the remove function.  Get rid of
> it in the i2c-mux-gpio driver.
> 
> See Stephen's comment at:
>   http://www.gossamer-threads.com/lists/linux/kernel/1678627?do=post_view_threaded#1678627
> 
> Signed-off-by: Doug Anderson <dianders@chromium.org>

I think we should do this at least I2C subsystem wide (51 occasions of
setting some *_drvdata to NULL), even better kernel-wide. Patching
individual drivers won't cut the confusion around this issue, I am
afraid.

Thanks,

   Wolfram

--
To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Doug Anderson Feb. 15, 2013, 7:43 p.m. UTC | #2
Wolfram,

On Fri, Feb 15, 2013 at 11:37 AM, Wolfram Sang <wsa@the-dreams.de> wrote:
> I think we should do this at least I2C subsystem wide (51 occasions of
> setting some *_drvdata to NULL), even better kernel-wide. Patching
> individual drivers won't cut the confusion around this issue, I am
> afraid.

I did it "mux" directory wide and this was the only instance.  ;)
I'll re-send with I2C subsystem wide.  I probably won't attempt the
whole kernel wide at this point, but would be very happy if someone
else wanted to!  :)

Thanks for the review!

-Doug
--
To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Wolfram Sang Feb. 15, 2013, 7:53 p.m. UTC | #3
> I'll re-send with I2C subsystem wide.  I probably won't attempt the
> whole kernel wide at this point, but would be very happy if someone
> else wanted to!  :)

Thanks. Please double check that setting NULL is really unneeded for the
non-platform-bus variants, too, or skip those if you are unsure. Please
also update the commit message to reference a stronger indication than
Stephen's "should not be necessary" ;) I do agree but for the commit
history, a better reference would be nice to educate readers.

Thanks,

   Wolfram

--
To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Doug Anderson Feb. 15, 2013, 11:17 p.m. UTC | #4
Wolfram,

On Fri, Feb 15, 2013 at 11:53 AM, Wolfram Sang <wsa@the-dreams.de> wrote:
>
>> I'll re-send with I2C subsystem wide.  I probably won't attempt the
>> whole kernel wide at this point, but would be very happy if someone
>> else wanted to!  :)
>
> Thanks. Please double check that setting NULL is really unneeded for the
> non-platform-bus variants, too, or skip those if you are unsure. Please
> also update the commit message to reference a stronger indication than
> Stephen's "should not be necessary" ;) I do agree but for the commit
> history, a better reference would be nice to educate readers.

Sounds good.

I've it looks like non-platform-bus instances in drivers/i2c break down to:
* dev_set_drvdata() directly (even though we're a platform device)
* pci_set_drvdata()
* amba_set_drvdata()
* serio_set_drvdata()

I'll go ahead and include those in my patch.  I've looked through the
code a bit.  While I can't 100% guarantee that there's not some
strange code path that I'm missing, it all looks pretty
straightforward.  A few points to be made:

* It would be a bit hard to believe that some higher-level code could
make any particular assumptions about the value in the pointer (it
might point to static data, kmalloced data, etc).  ...so if the
higher-level code is directly looking at this value it'd really could
only be looking to validate that the driver put NULL here.  I don't
see that anywhere.

* I've checked all of the calls to xxx_get_drvdata() in the drivers
touched.  The majority are in remove, suspend, or resume, so we're
good there.  In other cases I just validated that they aren't checking
for and relying on a NULL result of xxx_get_drvdata().

* It would be possible that some subsystem tries to be helpful and
call xxx_get_drvdata() for you and then pass drvdata into a callback
(so I wouldn't see xxx_get_drvdata()).  I don't see that (it would be
a strange design anyway IMHO).  Most of the time I2C devices seem to
get their private data from adap->algo_data anyway (or from the
pointer passed to IRQ registration) and xxx_set_drvdata() doesn't
touch those.

* The __device_release_driver() function actually calls the
"dev_set_drvdata(dev, NULL)" for you anyway.  ...and I that's what's
running the remove code anyway.  ...so we'd only need to worry about
code that could show up before that...


-Doug
--
To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/i2c/muxes/i2c-mux-gpio.c b/drivers/i2c/muxes/i2c-mux-gpio.c
index 9f50ef0..abc2e55a 100644
--- a/drivers/i2c/muxes/i2c-mux-gpio.c
+++ b/drivers/i2c/muxes/i2c-mux-gpio.c
@@ -250,7 +250,6 @@  static int i2c_mux_gpio_remove(struct platform_device *pdev)
 	for (i = 0; i < mux->data.n_gpios; i++)
 		gpio_free(mux->gpio_base + mux->data.gpios[i]);
 
-	platform_set_drvdata(pdev, NULL);
 	i2c_put_adapter(mux->parent);
 
 	return 0;