All of lore.kernel.org
 help / color / mirror / Atom feed
From: Thierry Reding <treding-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
To: Vladimir Zapolskiy
	<vladimir_zapolskiy-nmGgyN9QBj3QT0dZR+AlfA@public.gmane.org>
Cc: Wolfram Sang <wsa-z923LK4zBo2bacvFa/9K2g@public.gmane.org>,
	David Airlie <airlied-cv59FeDIM0c@public.gmane.org>,
	Philipp Zabel <p.zabel-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>,
	Russell King <rmk+kernel-lFZ/pmaqli7XmaaqVzeoHQ@public.gmane.org>,
	Andy Yan <andy.yan-TNX95d0MmH7DzftRWevZcw@public.gmane.org>,
	Fabio Estevam
	<fabio.estevam-KZfg59tc24xl57MIdRCFDg@public.gmane.org>,
	Inki Dae <inki.dae-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>,
	Benjamin Gaignard
	<benjamin.gaignard-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>,
	Tomi Valkeinen <tomi.valkeinen-l0cyMroinI0@public.gmane.org>,
	dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org,
	linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org
Subject: Re: [PATCH 01/10] i2c: add and export of_get_i2c_adapter_by_node() interface
Date: Wed, 8 Jul 2015 15:53:40 +0200	[thread overview]
Message-ID: <20150708135338.GB16082@ulmo.nvidia.com> (raw)
In-Reply-To: <559D2639.1030706-nmGgyN9QBj3QT0dZR+AlfA@public.gmane.org>

[-- Attachment #1: Type: text/plain, Size: 4024 bytes --]

On Wed, Jul 08, 2015 at 04:31:37PM +0300, Vladimir Zapolskiy wrote:
> Hi Thierry,
> 
> On 08.07.2015 16:11, Thierry Reding wrote:
> > On Wed, Jul 08, 2015 at 03:59:12PM +0300, Vladimir Zapolskiy wrote:
> >> of_find_i2c_adapter_by_node() call requires quite often missing
> >> put_device(), and i2c_put_adapter() releases a device locked by
> >> i2c_get_adapter() only. In general module_put(adapter->owner) and
> >> put_device(dev) are not interchangeable.
> >>
> >> This is a common error reproduction scenario as a result of the
> >> misusage described above (for clearness this is run on iMX6 platform
> >> with HDMI and I2C bus drivers compiled as kernel modules):
> >>
> >>     root@mx6q:~# lsmod | grep i2c
> >>     i2c_imx                10213  0
> >>     root@mx6q:~# lsmod | grep dw_hdmi_imx
> >>     dw_hdmi_imx             3631  0
> >>     dw_hdmi                11846  1 dw_hdmi_imx
> >>     imxdrm                  8674  3 dw_hdmi_imx,imx_ipuv3_crtc,imx_ldb
> >>     drm_kms_helper        113765  5 dw_hdmi,imxdrm,imx_ipuv3_crtc,imx_ldb
> >>     root@mx6q:~# rmmod dw_hdmi_imx
> >>     root@mx6q:~# lsmod | grep i2c
> >>     i2c_imx                10213  -1
> >>
> >>                                  ^^^^^
> >>
> >>     root@mx6q:~# rmmod i2c_imx
> >>     rmmod: ERROR: Module i2c_imx is in use
> >>
> >> To fix existing users of these interfaces and to avoid any further
> >> confusion and misusage in future, add one more interface
> >> of_get_i2c_adapter_by_node(), it is similar to i2c_get_adapter() in
> >> sense that an I2C bus device driver found and locked by user can be
> >> correctly unlocked by i2c_put_adapter().
> >>
> >> Signed-off-by: Vladimir Zapolskiy <vladimir_zapolskiy-nmGgyN9QBj3QT0dZR+AlfA@public.gmane.org>
> >> ---
> >> The change is based on RFC http://www.spinics.net/lists/linux-i2c/msg20257.html
> >>
> >> * added new exported function declaration in include/linux/i2c.h
> >> * added put_device(dev) call right inside of_get_i2c_adapter_by_node()
> >> * corrected authorship of the change
> >>
> >>  drivers/i2c/i2c-core.c | 20 ++++++++++++++++++++
> >>  include/linux/i2c.h    |  6 ++++++
> >>  2 files changed, 26 insertions(+)
> >>
> >> diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
> >> index 069a41f..0d902ab 100644
> >> --- a/drivers/i2c/i2c-core.c
> >> +++ b/drivers/i2c/i2c-core.c
> >> @@ -1356,6 +1356,26 @@ struct i2c_adapter *of_find_i2c_adapter_by_node(struct device_node *node)
> >>  	return i2c_verify_adapter(dev);
> >>  }
> >>  EXPORT_SYMBOL(of_find_i2c_adapter_by_node);
> >> +
> >> +struct i2c_adapter *of_get_i2c_adapter_by_node(struct device_node *node)
> >> +{
> >> +	struct device *dev;
> >> +	struct i2c_adapter *adapter;
> >> +
> >> +	dev = bus_find_device(&i2c_bus_type, NULL, node,
> >> +			      of_dev_node_match);
> >> +	if (!dev)
> >> +		return NULL;
> >> +
> >> +	adapter = i2c_verify_adapter(dev);
> >> +	if (adapter && !try_module_get(adapter->owner))
> >> +		adapter = NULL;
> >> +
> >> +	put_device(dev);
> > 
> > I don't think this is correct. Users still need to keep a reference to
> > the device, otherwise it can simply disappear even if the module stays
> > around (think sysfs bind/unbind attributes).
> > 
> > Looking at i2c_put_adapter() it seems like it would need to do more than
> > just drop the module reference. Then again, that probably means that we
> > need to add a get_device() somewhere in i2c_get_adapter() to balance the
> > put_device() in i2c_put_adapter().
> 
> it makes sense for me, thanks for momentary review.
> 
> I'm hesitating to add put_device(dev) to i2c_put_adapter() etc. in this
> series though. After development and testing I would like to send
> another preceding independent change updating i2c_get_adapter(),
> i2c_put_adapter() and clients (or if you wish you can do it), then I'll
> rebase 01/10 on top of it, the rest most probably is unchanged.

I think that would make sense, yes.

Thierry

[-- Attachment #2: Type: application/pgp-signature, Size: 819 bytes --]

WARNING: multiple messages have this Message-ID (diff)
From: treding@nvidia.com (Thierry Reding)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 01/10] i2c: add and export of_get_i2c_adapter_by_node() interface
Date: Wed, 8 Jul 2015 15:53:40 +0200	[thread overview]
Message-ID: <20150708135338.GB16082@ulmo.nvidia.com> (raw)
In-Reply-To: <559D2639.1030706@mentor.com>

On Wed, Jul 08, 2015 at 04:31:37PM +0300, Vladimir Zapolskiy wrote:
> Hi Thierry,
> 
> On 08.07.2015 16:11, Thierry Reding wrote:
> > On Wed, Jul 08, 2015 at 03:59:12PM +0300, Vladimir Zapolskiy wrote:
> >> of_find_i2c_adapter_by_node() call requires quite often missing
> >> put_device(), and i2c_put_adapter() releases a device locked by
> >> i2c_get_adapter() only. In general module_put(adapter->owner) and
> >> put_device(dev) are not interchangeable.
> >>
> >> This is a common error reproduction scenario as a result of the
> >> misusage described above (for clearness this is run on iMX6 platform
> >> with HDMI and I2C bus drivers compiled as kernel modules):
> >>
> >>     root at mx6q:~# lsmod | grep i2c
> >>     i2c_imx                10213  0
> >>     root at mx6q:~# lsmod | grep dw_hdmi_imx
> >>     dw_hdmi_imx             3631  0
> >>     dw_hdmi                11846  1 dw_hdmi_imx
> >>     imxdrm                  8674  3 dw_hdmi_imx,imx_ipuv3_crtc,imx_ldb
> >>     drm_kms_helper        113765  5 dw_hdmi,imxdrm,imx_ipuv3_crtc,imx_ldb
> >>     root at mx6q:~# rmmod dw_hdmi_imx
> >>     root at mx6q:~# lsmod | grep i2c
> >>     i2c_imx                10213  -1
> >>
> >>                                  ^^^^^
> >>
> >>     root at mx6q:~# rmmod i2c_imx
> >>     rmmod: ERROR: Module i2c_imx is in use
> >>
> >> To fix existing users of these interfaces and to avoid any further
> >> confusion and misusage in future, add one more interface
> >> of_get_i2c_adapter_by_node(), it is similar to i2c_get_adapter() in
> >> sense that an I2C bus device driver found and locked by user can be
> >> correctly unlocked by i2c_put_adapter().
> >>
> >> Signed-off-by: Vladimir Zapolskiy <vladimir_zapolskiy@mentor.com>
> >> ---
> >> The change is based on RFC http://www.spinics.net/lists/linux-i2c/msg20257.html
> >>
> >> * added new exported function declaration in include/linux/i2c.h
> >> * added put_device(dev) call right inside of_get_i2c_adapter_by_node()
> >> * corrected authorship of the change
> >>
> >>  drivers/i2c/i2c-core.c | 20 ++++++++++++++++++++
> >>  include/linux/i2c.h    |  6 ++++++
> >>  2 files changed, 26 insertions(+)
> >>
> >> diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
> >> index 069a41f..0d902ab 100644
> >> --- a/drivers/i2c/i2c-core.c
> >> +++ b/drivers/i2c/i2c-core.c
> >> @@ -1356,6 +1356,26 @@ struct i2c_adapter *of_find_i2c_adapter_by_node(struct device_node *node)
> >>  	return i2c_verify_adapter(dev);
> >>  }
> >>  EXPORT_SYMBOL(of_find_i2c_adapter_by_node);
> >> +
> >> +struct i2c_adapter *of_get_i2c_adapter_by_node(struct device_node *node)
> >> +{
> >> +	struct device *dev;
> >> +	struct i2c_adapter *adapter;
> >> +
> >> +	dev = bus_find_device(&i2c_bus_type, NULL, node,
> >> +			      of_dev_node_match);
> >> +	if (!dev)
> >> +		return NULL;
> >> +
> >> +	adapter = i2c_verify_adapter(dev);
> >> +	if (adapter && !try_module_get(adapter->owner))
> >> +		adapter = NULL;
> >> +
> >> +	put_device(dev);
> > 
> > I don't think this is correct. Users still need to keep a reference to
> > the device, otherwise it can simply disappear even if the module stays
> > around (think sysfs bind/unbind attributes).
> > 
> > Looking at i2c_put_adapter() it seems like it would need to do more than
> > just drop the module reference. Then again, that probably means that we
> > need to add a get_device() somewhere in i2c_get_adapter() to balance the
> > put_device() in i2c_put_adapter().
> 
> it makes sense for me, thanks for momentary review.
> 
> I'm hesitating to add put_device(dev) to i2c_put_adapter() etc. in this
> series though. After development and testing I would like to send
> another preceding independent change updating i2c_get_adapter(),
> i2c_put_adapter() and clients (or if you wish you can do it), then I'll
> rebase 01/10 on top of it, the rest most probably is unchanged.

I think that would make sense, yes.

Thierry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20150708/06f627f2/attachment.sig>

  parent reply	other threads:[~2015-07-08 13:53 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-08 12:54 [PATCH 00/10] i2c/drm: fix i2c adapter device driver user counter Vladimir Zapolskiy
2015-07-08 12:54 ` Vladimir Zapolskiy
2015-07-08 12:59 ` [PATCH 01/10] i2c: add and export of_get_i2c_adapter_by_node() interface Vladimir Zapolskiy
2015-07-08 12:59   ` Vladimir Zapolskiy
2015-07-08 13:11   ` Thierry Reding
2015-07-08 13:11     ` Thierry Reding
     [not found]     ` <20150708131140.GA12791-AwZRO8vwLAwmlAP/+Wk3EA@public.gmane.org>
2015-07-08 13:31       ` Vladimir Zapolskiy
2015-07-08 13:31         ` Vladimir Zapolskiy
     [not found]         ` <559D2639.1030706-nmGgyN9QBj3QT0dZR+AlfA@public.gmane.org>
2015-07-08 13:53           ` Thierry Reding [this message]
2015-07-08 13:53             ` Thierry Reding
2015-07-08 12:59 ` [PATCH 02/10] drm: dw_hdmi: use of_get_i2c_adapter_by_node interface Vladimir Zapolskiy
2015-07-08 12:59   ` Vladimir Zapolskiy
2015-07-08 12:59 ` [PATCH 03/10] drm: exynos_hdmi: " Vladimir Zapolskiy
2015-07-08 12:59   ` Vladimir Zapolskiy
     [not found] ` <1436360095-9065-1-git-send-email-vladimir_zapolskiy-nmGgyN9QBj3QT0dZR+AlfA@public.gmane.org>
2015-07-08 12:59   ` [PATCH 04/10] drm: imx-tve: " Vladimir Zapolskiy
2015-07-08 12:59     ` Vladimir Zapolskiy
2015-07-08 13:00   ` [PATCH 10/10] i2c: i2c-arb-gpio-challenge: " Vladimir Zapolskiy
2015-07-08 13:00     ` Vladimir Zapolskiy
2015-07-08 12:59 ` [PATCH 05/10] drm: panel-simple: " Vladimir Zapolskiy
2015-07-08 12:59   ` Vladimir Zapolskiy
2015-07-08 12:59 ` [PATCH 06/10] drm: sti_hdmi: " Vladimir Zapolskiy
2015-07-08 12:59   ` Vladimir Zapolskiy
2015-07-08 13:00 ` [PATCH 07/10] drm: tegra: " Vladimir Zapolskiy
2015-07-08 13:00   ` Vladimir Zapolskiy
2015-07-08 13:00 ` [PATCH 08/10] drm: tilcdc: " Vladimir Zapolskiy
2015-07-08 13:00   ` Vladimir Zapolskiy
2015-07-08 13:00 ` [PATCH 09/10] fbdev: omap2: connector-dvi: " Vladimir Zapolskiy
2015-07-08 13:00   ` Vladimir Zapolskiy
2015-07-08 13:00   ` Vladimir Zapolskiy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150708135338.GB16082@ulmo.nvidia.com \
    --to=treding-ddmlm1+adcrqt0dzr+alfa@public.gmane.org \
    --cc=airlied-cv59FeDIM0c@public.gmane.org \
    --cc=andy.yan-TNX95d0MmH7DzftRWevZcw@public.gmane.org \
    --cc=benjamin.gaignard-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org \
    --cc=dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org \
    --cc=fabio.estevam-KZfg59tc24xl57MIdRCFDg@public.gmane.org \
    --cc=inki.dae-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org \
    --cc=linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \
    --cc=linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=p.zabel-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org \
    --cc=rmk+kernel-lFZ/pmaqli7XmaaqVzeoHQ@public.gmane.org \
    --cc=tomi.valkeinen-l0cyMroinI0@public.gmane.org \
    --cc=vladimir_zapolskiy-nmGgyN9QBj3QT0dZR+AlfA@public.gmane.org \
    --cc=wsa-z923LK4zBo2bacvFa/9K2g@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.