linux-i2c.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/6]  Make return type of i2c_del_adapter() (and i2c_del_mux_adapter()) void
@ 2013-03-09 18:16 Lars-Peter Clausen
  2013-03-09 18:16 ` [PATCH 1/6] i2c: Remove detach_adapter Lars-Peter Clausen
                   ` (7 more replies)
  0 siblings, 8 replies; 26+ messages in thread
From: Lars-Peter Clausen @ 2013-03-09 18:16 UTC (permalink / raw)
  To: Wolfram Sang, Ben Dooks; +Cc: linux-i2c, linux-kernel, Lars-Peter Clausen

Currently i2c_del_adapter() returns 0 on success and potentially an error code
on failure. Unfortunately this doesn't mix too well with the Linux device driver
model. An i2c_adapter is usually registered in a drivers probe callback and
removed in the drivers remove callback. The Linux device driver model assumes
that a device may disappear at any time, e.g. because it is on a hot-plug-able
bus and the device is physically removed or because it is unbound from it's
driver. This means that a driver's remove callback is not allowed to fail. This
has lead to code fragments like the following:

	rc = i2c_del_adapter(&board->i2c_adap);
	BUG_ON(rc);

Currently there are two code paths which can cause to i2c_del_adapter() to
return an error code:
1) If the adapter that is passed to i2c_del_adapter() is not registered
i2c_del_adapter() returns -EINVAL
2) If an I2C client, which is registered as a child to the adapter, implements
the detach_adapter callback and detach_adapter returns an error the removal of
the adapter is aborted and i2c_del_adapter() returns the error returned by the
clients detach_adapter callback.

The first probably never happens unless there is a serious bug in the driver
calling i2c_del_adapter(), but I think even then, for the sake of sanitizing the
API we can argue that the purpose of i2c_del_adapter() is to remove the adapter
from the system. If the adapter currently isn't registered this becomes a no-op
and we can return success, without having to do anything. The second also never
happens, since the detach_adapter callback has been deprecated for quite some
time now and there are currently no drivers left which implement it.

So realisticly i2c_del_adapter() already always returns 0 and all code checking
for errors is more or less dead code. And in fact the majority of the users of
i2c_del_adapter() already ignore the return value, but there are still some
drivers (both newer and older) which assume that i2c_del_adapter() might fail.
This series aims at making it explicit that i2c_del_adapter() can not fail by
making its return type void.

The series will start by making i2c_del_adapter() always return success. For
this it will update the case, where a non-registered adapter is passed in, to
return 0 instead of -EINVAL and remove all code related to the unused
detach_adapter callback. Afterward the series will update all users of
i2c_del_adapter() to ignore the return value (since it is always 0 now). And
finally the series will change the return type of i2c_del_adapter() to void.

The same is true for i2c_del_mux_adapter() which is mostly just a wrapper
around i2c_del_adapter(), so it is also updated in this series.

- Lars

Lars-Peter Clausen (6):
  i2c: Remove detach_adapter
  i2c: i2c_del_adapter: Don't treat removing a non-registered adapter
    as error
  i2c: Ignore return value of i2c_del_adapter()
  i2c: Make return type of i2c_del_adapter() void
  i2c: Ignore the return value of i2c_del_mux_adapter()
  i2c: Make the return type of i2c_del_mux_adapter() void

 drivers/gpu/drm/gma500/oaktrail_hdmi_i2c.c   |  3 +--
 drivers/i2c/busses/i2c-amd756-s4882.c        |  6 +----
 drivers/i2c/busses/i2c-at91.c                |  5 ++--
 drivers/i2c/busses/i2c-cbus-gpio.c           |  4 ++-
 drivers/i2c/busses/i2c-intel-mid.c           |  3 +--
 drivers/i2c/busses/i2c-mv64xxx.c             |  5 ++--
 drivers/i2c/busses/i2c-mxs.c                 |  5 +---
 drivers/i2c/busses/i2c-nforce2-s4985.c       |  6 +----
 drivers/i2c/busses/i2c-powermac.c            | 10 ++-----
 drivers/i2c/busses/i2c-puv3.c                | 10 ++-----
 drivers/i2c/busses/i2c-viperboard.c          |  5 ++--
 drivers/i2c/i2c-core.c                       | 39 +++++++++-------------------
 drivers/i2c/i2c-mux.c                        |  9 ++-----
 drivers/i2c/muxes/i2c-mux-pca954x.c          |  6 ++---
 drivers/media/pci/bt8xx/bttv-input.c         |  6 ++---
 drivers/media/pci/mantis/mantis_i2c.c        |  4 ++-
 drivers/net/ethernet/sfc/falcon.c            |  6 ++---
 drivers/staging/media/go7007/go7007-driver.c |  7 ++---
 include/linux/i2c-mux.h                      |  2 +-
 include/linux/i2c.h                          |  9 +++----
 20 files changed, 48 insertions(+), 102 deletions(-)

-- 
1.8.0

^ permalink raw reply	[flat|nested] 26+ messages in thread

end of thread, other threads:[~2013-04-02  5:09 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-03-09 18:16 [PATCH 0/6] Make return type of i2c_del_adapter() (and i2c_del_mux_adapter()) void Lars-Peter Clausen
2013-03-09 18:16 ` [PATCH 1/6] i2c: Remove detach_adapter Lars-Peter Clausen
     [not found]   ` <1362853009-20789-2-git-send-email-lars-Qo5EllUWu/uELgA04lAiVw@public.gmane.org>
2013-03-30 14:52     ` Jean Delvare
2013-03-09 18:16 ` [PATCH 2/6] i2c: i2c_del_adapter: Don't treat removing a non-registered adapter as error Lars-Peter Clausen
     [not found]   ` <1362853009-20789-3-git-send-email-lars-Qo5EllUWu/uELgA04lAiVw@public.gmane.org>
2013-03-30 18:17     ` Jean Delvare
2013-03-09 18:16 ` [PATCH 3/6] i2c: Ignore return value of i2c_del_adapter() Lars-Peter Clausen
     [not found]   ` <1362853009-20789-4-git-send-email-lars-Qo5EllUWu/uELgA04lAiVw@public.gmane.org>
2013-03-11 17:52     ` Ben Hutchings
2013-03-30  6:34     ` Wolfram Sang
2013-03-30  7:55     ` Jean Delvare
     [not found]       ` <20130330085539.442321fa-R0o5gVi9kd7kN2dkZ6Wm7A@public.gmane.org>
2013-03-30  8:11         ` Lars-Peter Clausen
     [not found]           ` <51569E4A.2080006-Qo5EllUWu/uELgA04lAiVw@public.gmane.org>
2013-03-30  8:43             ` Jean Delvare
2013-03-31 13:12     ` Shawn Guo
2013-03-31  8:25   ` Jean Delvare
2013-03-09 18:16 ` [PATCH 4/6] i2c: Make return type of i2c_del_adapter() void Lars-Peter Clausen
     [not found]   ` <1362853009-20789-5-git-send-email-lars-Qo5EllUWu/uELgA04lAiVw@public.gmane.org>
2013-03-31  9:04     ` Jean Delvare
2013-03-09 18:16 ` [PATCH 5/6] i2c: Ignore the return value of i2c_del_mux_adapter() Lars-Peter Clausen
     [not found]   ` <1362853009-20789-6-git-send-email-lars-Qo5EllUWu/uELgA04lAiVw@public.gmane.org>
2013-03-13  6:05     ` [5/6] " Guenter Roeck
2013-03-31  9:23     ` [PATCH 5/6] " Jean Delvare
2013-03-09 18:16 ` [PATCH 6/6] i2c: Make the return type of i2c_del_mux_adapter() void Lars-Peter Clausen
     [not found]   ` <1362853009-20789-7-git-send-email-lars-Qo5EllUWu/uELgA04lAiVw@public.gmane.org>
2013-03-31  9:24     ` Jean Delvare
2013-03-30  6:33 ` [PATCH 0/6] Make return type of i2c_del_adapter() (and i2c_del_mux_adapter()) void Wolfram Sang
     [not found] ` <1362853009-20789-1-git-send-email-lars-Qo5EllUWu/uELgA04lAiVw@public.gmane.org>
2013-03-30 20:13   ` Jean Delvare
2013-03-30 20:43     ` Lars-Peter Clausen
     [not found]       ` <51574E71.7010403-Qo5EllUWu/uELgA04lAiVw@public.gmane.org>
2013-03-31  7:56         ` Jean Delvare
2013-03-31 11:30   ` Jean Delvare
2013-04-02  5:09   ` Wolfram Sang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).