* [PATCH v2 0/4] i2c: fix i2c adapter device driver user counter
@ 2015-07-27 14:30 Vladimir Zapolskiy
[not found] ` <1438007451-8553-1-git-send-email-vladimir_zapolskiy-nmGgyN9QBj3QT0dZR+AlfA@public.gmane.org>
0 siblings, 1 reply; 12+ messages in thread
From: Vladimir Zapolskiy @ 2015-07-27 14:30 UTC (permalink / raw)
To: Wolfram Sang, Thierry Reding; +Cc: linux-i2c-u79uwXL29TY76Z2rM5mHXA
The series fixes i2c bus device refcounting for clients of i2c_get_adapter(),
of_find_i2c_adapter_by_node() and of_find_i2c_device_by_node() interfaces.
The v2 3/4 change adds and exports new of_get_i2c_adapter_by_node()
interface of i2c core, v2 4/4 is an unchanged version of v1 10/10, which
utilizes this new interface in order to fix the refcounting bug described
below in detail.
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 (this is run on iMX6 platform with
HDMI and I2C bus drivers compiled as kernel modules for clearness):
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().
Mainly the change is addressed to multiple DRM users of I2C bus device
interfaces, but at the moment just one client inside drivers/i2c/* is fixed.
The change is based on Wolfram's i2c/for-next branch, 19e0ff42338
Changes from v1 to v2:
* added two more patches 1/4 and 2/4 fixing i2c bus device refcounting,
thanks to Thierry for the idea of 2/4 change,
* rebased v1 1/10 on top of v2 1/4 and v2 2/4, removed put_device()
from of_get_i2c_adapter_by_node() as suggested by Thierry,
* defer changes in 8 broken DRM and fbdev clients until i2c-core changes
are added to linux-next (or preferably 4.2.0-rc Linus' branch, if possible)
to improve signal/noise ratio on mailing lists.
v1 of the series with fixes on client side can be found at
http://permalink.gmane.org/gmane.linux.drivers.i2c/23652
RFC of the v1 01/10 change is http://www.spinics.net/lists/linux-i2c/msg20257.html
Vladimir Zapolskiy (4):
i2c: core: fix leaked device refcount on of_find_i2c_* error path
i2c: core: manage i2c bus device refcount in i2c_[get|put]_adapter
i2c: core: add and export of_get_i2c_adapter_by_node() interface
i2c: arb-gpio-challenge: use of_get_i2c_adapter_by_node interface
drivers/i2c/i2c-core.c | 53 +++++++++++++++++++++++++-----
drivers/i2c/muxes/i2c-arb-gpio-challenge.c | 3 +-
include/linux/i2c.h | 7 ++++
3 files changed, 53 insertions(+), 10 deletions(-)
--
2.1.4
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH v2 1/4] i2c: core: fix leaked device refcount on of_find_i2c_* error path
[not found] ` <1438007451-8553-1-git-send-email-vladimir_zapolskiy-nmGgyN9QBj3QT0dZR+AlfA@public.gmane.org>
@ 2015-07-27 14:30 ` Vladimir Zapolskiy
[not found] ` <1438007451-8553-2-git-send-email-vladimir_zapolskiy-nmGgyN9QBj3QT0dZR+AlfA@public.gmane.org>
2015-07-27 14:30 ` [PATCH v2 2/4] i2c: core: manage i2c bus device refcount in i2c_[get|put]_adapter Vladimir Zapolskiy
` (3 subsequent siblings)
4 siblings, 1 reply; 12+ messages in thread
From: Vladimir Zapolskiy @ 2015-07-27 14:30 UTC (permalink / raw)
To: Wolfram Sang, Thierry Reding; +Cc: linux-i2c-u79uwXL29TY76Z2rM5mHXA
If of_find_i2c_device_by_node() or of_find_i2c_adapter_by_node() find
a device by node, but its type does not match, a reference to that
device is still held. This change fixes the problem.
Signed-off-by: Vladimir Zapolskiy <vladimir_zapolskiy-nmGgyN9QBj3QT0dZR+AlfA@public.gmane.org>
---
Changes from v1 to v2:
* none, new change
drivers/i2c/i2c-core.c | 20 ++++++++++++++------
1 file changed, 14 insertions(+), 6 deletions(-)
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index e6d4935..d5fe5a4 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -1338,13 +1338,17 @@ static int of_dev_node_match(struct device *dev, void *data)
struct i2c_client *of_find_i2c_device_by_node(struct device_node *node)
{
struct device *dev;
+ struct i2c_client *client;
- dev = bus_find_device(&i2c_bus_type, NULL, node,
- of_dev_node_match);
+ dev = bus_find_device(&i2c_bus_type, NULL, node, of_dev_node_match);
if (!dev)
return NULL;
- return i2c_verify_client(dev);
+ client = i2c_verify_client(dev);
+ if (!client)
+ put_device(dev);
+
+ return client;
}
EXPORT_SYMBOL(of_find_i2c_device_by_node);
@@ -1352,13 +1356,17 @@ EXPORT_SYMBOL(of_find_i2c_device_by_node);
struct i2c_adapter *of_find_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);
+ dev = bus_find_device(&i2c_bus_type, NULL, node, of_dev_node_match);
if (!dev)
return NULL;
- return i2c_verify_adapter(dev);
+ adapter = i2c_verify_adapter(dev);
+ if (!adapter)
+ put_device(dev);
+
+ return adapter;
}
EXPORT_SYMBOL(of_find_i2c_adapter_by_node);
#else
--
2.1.4
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH v2 2/4] i2c: core: manage i2c bus device refcount in i2c_[get|put]_adapter
[not found] ` <1438007451-8553-1-git-send-email-vladimir_zapolskiy-nmGgyN9QBj3QT0dZR+AlfA@public.gmane.org>
2015-07-27 14:30 ` [PATCH v2 1/4] i2c: core: fix leaked device refcount on of_find_i2c_* error path Vladimir Zapolskiy
@ 2015-07-27 14:30 ` Vladimir Zapolskiy
[not found] ` <1438007451-8553-3-git-send-email-vladimir_zapolskiy-nmGgyN9QBj3QT0dZR+AlfA@public.gmane.org>
2015-07-27 14:30 ` [PATCH v2 3/4] i2c: core: add and export of_get_i2c_adapter_by_node() interface Vladimir Zapolskiy
` (2 subsequent siblings)
4 siblings, 1 reply; 12+ messages in thread
From: Vladimir Zapolskiy @ 2015-07-27 14:30 UTC (permalink / raw)
To: Wolfram Sang, Thierry Reding; +Cc: linux-i2c-u79uwXL29TY76Z2rM5mHXA
In addition to module_get()/module_put() add get_device()/put_device()
calls into i2c_get_adapter()/i2c_put_adapter() exported
interfaces. This is done to lock I2C bus device, if it is in use by a
client.
Signed-off-by: Vladimir Zapolskiy <vladimir_zapolskiy-nmGgyN9QBj3QT0dZR+AlfA@public.gmane.org>
---
Changes from v1 to v2:
* none, new change suggested by Thierry
drivers/i2c/i2c-core.c | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index d5fe5a4..a7054ac 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -2411,9 +2411,15 @@ struct i2c_adapter *i2c_get_adapter(int nr)
mutex_lock(&core_lock);
adapter = idr_find(&i2c_adapter_idr, nr);
- if (adapter && !try_module_get(adapter->owner))
+ if (!adapter)
+ goto exit;
+
+ if (try_module_get(adapter->owner))
+ get_device(&adapter->dev);
+ else
adapter = NULL;
+ exit:
mutex_unlock(&core_lock);
return adapter;
}
@@ -2421,8 +2427,11 @@ EXPORT_SYMBOL(i2c_get_adapter);
void i2c_put_adapter(struct i2c_adapter *adap)
{
- if (adap)
- module_put(adap->owner);
+ if (!adap)
+ return;
+
+ put_device(&adap->dev);
+ module_put(adap->owner);
}
EXPORT_SYMBOL(i2c_put_adapter);
--
2.1.4
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH v2 3/4] i2c: core: add and export of_get_i2c_adapter_by_node() interface
[not found] ` <1438007451-8553-1-git-send-email-vladimir_zapolskiy-nmGgyN9QBj3QT0dZR+AlfA@public.gmane.org>
2015-07-27 14:30 ` [PATCH v2 1/4] i2c: core: fix leaked device refcount on of_find_i2c_* error path Vladimir Zapolskiy
2015-07-27 14:30 ` [PATCH v2 2/4] i2c: core: manage i2c bus device refcount in i2c_[get|put]_adapter Vladimir Zapolskiy
@ 2015-07-27 14:30 ` Vladimir Zapolskiy
[not found] ` <1438007451-8553-4-git-send-email-vladimir_zapolskiy-nmGgyN9QBj3QT0dZR+AlfA@public.gmane.org>
2015-07-27 14:30 ` [PATCH v2 4/4] i2c: arb-gpio-challenge: use of_get_i2c_adapter_by_node interface Vladimir Zapolskiy
2015-08-01 10:09 ` [PATCH v2 0/4] i2c: fix i2c adapter device driver user counter Wolfram Sang
4 siblings, 1 reply; 12+ messages in thread
From: Vladimir Zapolskiy @ 2015-07-27 14:30 UTC (permalink / raw)
To: Wolfram Sang, Thierry Reding; +Cc: linux-i2c-u79uwXL29TY76Z2rM5mHXA
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>
---
Changes from v1 to v2:
* rebased v1 1/10 on top of v2 1/4 and v2 2/4, removed put_device()
from of_get_i2c_adapter_by_node() as suggested by Thierry
* reuse of_find_i2c_adapter_by_node() to replace common code
* fix potential device refcount leakage on error path
Changes from RFC to v1:
* 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 | 18 ++++++++++++++++++
include/linux/i2c.h | 7 +++++++
2 files changed, 25 insertions(+)
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index a7054ac..f3de2e1 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -1369,6 +1369,24 @@ struct i2c_adapter *of_find_i2c_adapter_by_node(struct device_node *node)
return adapter;
}
EXPORT_SYMBOL(of_find_i2c_adapter_by_node);
+
+/* must call i2c_put_adapter() when done with returned i2c_adapter device */
+struct i2c_adapter *of_get_i2c_adapter_by_node(struct device_node *node)
+{
+ struct i2c_adapter *adapter;
+
+ adapter = of_find_i2c_adapter_by_node(node);
+ if (!adapter)
+ return NULL;
+
+ if (!try_module_get(adapter->owner)) {
+ put_device(&adapter->dev);
+ adapter = NULL;
+ }
+
+ return adapter;
+}
+EXPORT_SYMBOL(of_get_i2c_adapter_by_node);
#else
static void of_i2c_register_devices(struct i2c_adapter *adap) { }
#endif /* CONFIG_OF */
diff --git a/include/linux/i2c.h b/include/linux/i2c.h
index e83a738..e2c859b 100644
--- a/include/linux/i2c.h
+++ b/include/linux/i2c.h
@@ -638,6 +638,8 @@ extern struct i2c_client *of_find_i2c_device_by_node(struct device_node *node);
/* must call put_device() when done with returned i2c_adapter device */
extern struct i2c_adapter *of_find_i2c_adapter_by_node(struct device_node *node);
+/* must call i2c_put_adapter() when done with returned i2c_adapter device */
+struct i2c_adapter *of_get_i2c_adapter_by_node(struct device_node *node);
#else
static inline struct i2c_client *of_find_i2c_device_by_node(struct device_node *node)
@@ -649,6 +651,11 @@ static inline struct i2c_adapter *of_find_i2c_adapter_by_node(struct device_node
{
return NULL;
}
+
+static inline struct i2c_adapter *of_get_i2c_adapter_by_node(struct device_node *node)
+{
+ return NULL;
+}
#endif /* CONFIG_OF */
#endif /* _LINUX_I2C_H */
--
2.1.4
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH v2 4/4] i2c: arb-gpio-challenge: use of_get_i2c_adapter_by_node interface
[not found] ` <1438007451-8553-1-git-send-email-vladimir_zapolskiy-nmGgyN9QBj3QT0dZR+AlfA@public.gmane.org>
` (2 preceding siblings ...)
2015-07-27 14:30 ` [PATCH v2 3/4] i2c: core: add and export of_get_i2c_adapter_by_node() interface Vladimir Zapolskiy
@ 2015-07-27 14:30 ` Vladimir Zapolskiy
[not found] ` <1438007451-8553-5-git-send-email-vladimir_zapolskiy-nmGgyN9QBj3QT0dZR+AlfA@public.gmane.org>
2015-08-01 10:09 ` [PATCH v2 0/4] i2c: fix i2c adapter device driver user counter Wolfram Sang
4 siblings, 1 reply; 12+ messages in thread
From: Vladimir Zapolskiy @ 2015-07-27 14:30 UTC (permalink / raw)
To: Wolfram Sang, Thierry Reding
Cc: linux-i2c-u79uwXL29TY76Z2rM5mHXA, Doug Anderson
This change is needed to properly lock I2C parent bus driver.
Prior to this change i2c_put_adapter() is misused, which may lead
to an overflow over zero of I2C bus driver user counter.
By the way added a missing of_node_put() to eliminate memory leak,
if OF_DYNAMIC is enabled.
Signed-off-by: Vladimir Zapolskiy <vladimir_zapolskiy-nmGgyN9QBj3QT0dZR+AlfA@public.gmane.org>
Cc: Doug Anderson <dianders-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
---
Changes from v1 to v2:
* none, the same change as v1 10/10
drivers/i2c/muxes/i2c-arb-gpio-challenge.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/i2c/muxes/i2c-arb-gpio-challenge.c b/drivers/i2c/muxes/i2c-arb-gpio-challenge.c
index 5cf1b60..402e3a6 100644
--- a/drivers/i2c/muxes/i2c-arb-gpio-challenge.c
+++ b/drivers/i2c/muxes/i2c-arb-gpio-challenge.c
@@ -196,7 +196,8 @@ static int i2c_arbitrator_probe(struct platform_device *pdev)
dev_err(dev, "Cannot parse i2c-parent\n");
return -EINVAL;
}
- arb->parent = of_find_i2c_adapter_by_node(parent_np);
+ arb->parent = of_get_i2c_adapter_by_node(parent_np);
+ of_node_put(parent_np);
if (!arb->parent) {
dev_err(dev, "Cannot find parent bus\n");
return -EPROBE_DEFER;
--
2.1.4
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH v2 0/4] i2c: fix i2c adapter device driver user counter
[not found] ` <1438007451-8553-1-git-send-email-vladimir_zapolskiy-nmGgyN9QBj3QT0dZR+AlfA@public.gmane.org>
` (3 preceding siblings ...)
2015-07-27 14:30 ` [PATCH v2 4/4] i2c: arb-gpio-challenge: use of_get_i2c_adapter_by_node interface Vladimir Zapolskiy
@ 2015-08-01 10:09 ` Wolfram Sang
2015-08-01 23:37 ` Vladimir Zapolskiy
4 siblings, 1 reply; 12+ messages in thread
From: Wolfram Sang @ 2015-08-01 10:09 UTC (permalink / raw)
To: Vladimir Zapolskiy; +Cc: Thierry Reding, linux-i2c-u79uwXL29TY76Z2rM5mHXA
[-- Attachment #1: Type: text/plain, Size: 1864 bytes --]
On Mon, Jul 27, 2015 at 05:30:47PM +0300, Vladimir Zapolskiy wrote:
> The series fixes i2c bus device refcounting for clients of i2c_get_adapter(),
> of_find_i2c_adapter_by_node() and of_find_i2c_device_by_node() interfaces.
Yay, thanks for working on that!
> The v2 3/4 change adds and exports new of_get_i2c_adapter_by_node()
> interface of i2c core, v2 4/4 is an unchanged version of v1 10/10, which
> utilizes this new interface in order to fix the refcounting bug described
> below in detail.
And thanks for the good descriptions, too.
> 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().
I tend to agree to the idea of the new function, should be less error
prone to users. Need to think about it a day more, though.
> Changes from v1 to v2:
> * added two more patches 1/4 and 2/4 fixing i2c bus device refcounting,
> thanks to Thierry for the idea of 2/4 change,
I'll apply 1/4 to for-current, since this is a clear bugfix. 2/4 seems
very worthwhile, too, but seems like less a bugfix to me; while it
changes things to be more correct, it also is a preparation for the
following patches.
> * defer changes in 8 broken DRM and fbdev clients until i2c-core changes
> are added to linux-next (or preferably 4.2.0-rc Linus' branch, if possible)
> to improve signal/noise ratio on mailing lists.
That was a clever thing to do. However, my gut feeling is that these
changes to refcounting behaviour should go via the next merge window to
get proper testing. If you guys want that in 4.2, then I would need a
lot of Tested, Acked, and Reviewed-by tags very soon.
Thanks again,
Wolfram
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v2 1/4] i2c: core: fix leaked device refcount on of_find_i2c_* error path
[not found] ` <1438007451-8553-2-git-send-email-vladimir_zapolskiy-nmGgyN9QBj3QT0dZR+AlfA@public.gmane.org>
@ 2015-08-01 10:09 ` Wolfram Sang
0 siblings, 0 replies; 12+ messages in thread
From: Wolfram Sang @ 2015-08-01 10:09 UTC (permalink / raw)
To: Vladimir Zapolskiy; +Cc: Thierry Reding, linux-i2c-u79uwXL29TY76Z2rM5mHXA
[-- Attachment #1: Type: text/plain, Size: 407 bytes --]
On Mon, Jul 27, 2015 at 05:30:48PM +0300, Vladimir Zapolskiy wrote:
> If of_find_i2c_device_by_node() or of_find_i2c_adapter_by_node() find
> a device by node, but its type does not match, a reference to that
> device is still held. This change fixes the problem.
>
> Signed-off-by: Vladimir Zapolskiy <vladimir_zapolskiy-nmGgyN9QBj3QT0dZR+AlfA@public.gmane.org>
Applied to for-current, thanks!
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v2 0/4] i2c: fix i2c adapter device driver user counter
2015-08-01 10:09 ` [PATCH v2 0/4] i2c: fix i2c adapter device driver user counter Wolfram Sang
@ 2015-08-01 23:37 ` Vladimir Zapolskiy
0 siblings, 0 replies; 12+ messages in thread
From: Vladimir Zapolskiy @ 2015-08-01 23:37 UTC (permalink / raw)
To: Wolfram Sang
Cc: Vladimir Zapolskiy, Thierry Reding,
linux-i2c-u79uwXL29TY76Z2rM5mHXA
Hi Wolfram,
On 01.08.2015 13:09, Wolfram Sang wrote:
> On Mon, Jul 27, 2015 at 05:30:47PM +0300, Vladimir Zapolskiy wrote:
>> The series fixes i2c bus device refcounting for clients of i2c_get_adapter(),
>> of_find_i2c_adapter_by_node() and of_find_i2c_device_by_node() interfaces.
>
> Yay, thanks for working on that!
>
>> The v2 3/4 change adds and exports new of_get_i2c_adapter_by_node()
>> interface of i2c core, v2 4/4 is an unchanged version of v1 10/10, which
>> utilizes this new interface in order to fix the refcounting bug described
>> below in detail.
>
> And thanks for the good descriptions, too.
>
>> 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().
>
> I tend to agree to the idea of the new function, should be less error
> prone to users. Need to think about it a day more, though.
>
>> Changes from v1 to v2:
>> * added two more patches 1/4 and 2/4 fixing i2c bus device refcounting,
>> thanks to Thierry for the idea of 2/4 change,
>
> I'll apply 1/4 to for-current, since this is a clear bugfix. 2/4 seems
> very worthwhile, too, but seems like less a bugfix to me; while it
> changes things to be more correct, it also is a preparation for the
> following patches.
>
>> * defer changes in 8 broken DRM and fbdev clients until i2c-core changes
>> are added to linux-next (or preferably 4.2.0-rc Linus' branch, if possible)
>> to improve signal/noise ratio on mailing lists.
>
> That was a clever thing to do. However, my gut feeling is that these
> changes to refcounting behaviour should go via the next merge window to
> get proper testing. If you guys want that in 4.2, then I would need a
> lot of Tested, Acked, and Reviewed-by tags very soon.
>
thank you for review, I'm fine if the rest of the changes enters
linux-next, after that, when drm-next picks them up, I'll send fixes to
the clients.
--
With best wishes,
Vladimir
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v2 2/4] i2c: core: manage i2c bus device refcount in i2c_[get|put]_adapter
[not found] ` <1438007451-8553-3-git-send-email-vladimir_zapolskiy-nmGgyN9QBj3QT0dZR+AlfA@public.gmane.org>
@ 2015-08-06 0:50 ` Wolfram Sang
0 siblings, 0 replies; 12+ messages in thread
From: Wolfram Sang @ 2015-08-06 0:50 UTC (permalink / raw)
To: Vladimir Zapolskiy; +Cc: Thierry Reding, linux-i2c-u79uwXL29TY76Z2rM5mHXA
[-- Attachment #1: Type: text/plain, Size: 422 bytes --]
On Mon, Jul 27, 2015 at 05:30:49PM +0300, Vladimir Zapolskiy wrote:
> In addition to module_get()/module_put() add get_device()/put_device()
> calls into i2c_get_adapter()/i2c_put_adapter() exported
> interfaces. This is done to lock I2C bus device, if it is in use by a
> client.
>
> Signed-off-by: Vladimir Zapolskiy <vladimir_zapolskiy-nmGgyN9QBj3QT0dZR+AlfA@public.gmane.org>
Applied to for-next, thanks!
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v2 3/4] i2c: core: add and export of_get_i2c_adapter_by_node() interface
[not found] ` <1438007451-8553-4-git-send-email-vladimir_zapolskiy-nmGgyN9QBj3QT0dZR+AlfA@public.gmane.org>
@ 2015-08-06 0:50 ` Wolfram Sang
0 siblings, 0 replies; 12+ messages in thread
From: Wolfram Sang @ 2015-08-06 0:50 UTC (permalink / raw)
To: Vladimir Zapolskiy; +Cc: Thierry Reding, linux-i2c-u79uwXL29TY76Z2rM5mHXA
[-- Attachment #1: Type: text/plain, Size: 1588 bytes --]
On Mon, Jul 27, 2015 at 05:30:50PM +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>
Applied to for-next, thanks!
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v2 4/4] i2c: arb-gpio-challenge: use of_get_i2c_adapter_by_node interface
[not found] ` <1438007451-8553-5-git-send-email-vladimir_zapolskiy-nmGgyN9QBj3QT0dZR+AlfA@public.gmane.org>
@ 2015-08-06 0:51 ` Wolfram Sang
2015-08-06 10:18 ` Vladimir Zapolskiy
0 siblings, 1 reply; 12+ messages in thread
From: Wolfram Sang @ 2015-08-06 0:51 UTC (permalink / raw)
To: Vladimir Zapolskiy
Cc: Thierry Reding, linux-i2c-u79uwXL29TY76Z2rM5mHXA, Doug Anderson
[-- Attachment #1: Type: text/plain, Size: 734 bytes --]
On Mon, Jul 27, 2015 at 05:30:51PM +0300, Vladimir Zapolskiy wrote:
> This change is needed to properly lock I2C parent bus driver.
>
> Prior to this change i2c_put_adapter() is misused, which may lead
> to an overflow over zero of I2C bus driver user counter.
>
> By the way added a missing of_node_put() to eliminate memory leak,
> if OF_DYNAMIC is enabled.
>
> Signed-off-by: Vladimir Zapolskiy <vladimir_zapolskiy-nmGgyN9QBj3QT0dZR+AlfA@public.gmane.org>
> Cc: Doug Anderson <dianders-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
Applied to for-next! However...
> + of_node_put(parent_np);
I removed this line. Please resend this as a seperate patch since it
fixes a seperate issue.
Thanks,
Wolfram
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v2 4/4] i2c: arb-gpio-challenge: use of_get_i2c_adapter_by_node interface
2015-08-06 0:51 ` Wolfram Sang
@ 2015-08-06 10:18 ` Vladimir Zapolskiy
0 siblings, 0 replies; 12+ messages in thread
From: Vladimir Zapolskiy @ 2015-08-06 10:18 UTC (permalink / raw)
To: Wolfram Sang
Cc: Thierry Reding, linux-i2c-u79uwXL29TY76Z2rM5mHXA, Doug Anderson
Hi Wolfram,
On 06.08.2015 03:51, Wolfram Sang wrote:
> On Mon, Jul 27, 2015 at 05:30:51PM +0300, Vladimir Zapolskiy wrote:
>> This change is needed to properly lock I2C parent bus driver.
>>
>> Prior to this change i2c_put_adapter() is misused, which may lead
>> to an overflow over zero of I2C bus driver user counter.
>>
>> By the way added a missing of_node_put() to eliminate memory leak,
>> if OF_DYNAMIC is enabled.
>>
>> Signed-off-by: Vladimir Zapolskiy <vladimir_zapolskiy-nmGgyN9QBj3QT0dZR+AlfA@public.gmane.org>
>> Cc: Doug Anderson <dianders-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
>
> Applied to for-next! However...
great, thank you.
>> + of_node_put(parent_np);
>
> I removed this line. Please resend this as a seperate patch since it
> fixes a seperate issue.
>
Definitely, I always forget about non-zero probability of any commit
reverse. I'll resend this change plus at least two more similar fixes in
drivers/i2c I have in mind in a separate series.
--
With best wishes,
Vladimir
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2015-08-06 10:18 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-07-27 14:30 [PATCH v2 0/4] i2c: fix i2c adapter device driver user counter Vladimir Zapolskiy
[not found] ` <1438007451-8553-1-git-send-email-vladimir_zapolskiy-nmGgyN9QBj3QT0dZR+AlfA@public.gmane.org>
2015-07-27 14:30 ` [PATCH v2 1/4] i2c: core: fix leaked device refcount on of_find_i2c_* error path Vladimir Zapolskiy
[not found] ` <1438007451-8553-2-git-send-email-vladimir_zapolskiy-nmGgyN9QBj3QT0dZR+AlfA@public.gmane.org>
2015-08-01 10:09 ` Wolfram Sang
2015-07-27 14:30 ` [PATCH v2 2/4] i2c: core: manage i2c bus device refcount in i2c_[get|put]_adapter Vladimir Zapolskiy
[not found] ` <1438007451-8553-3-git-send-email-vladimir_zapolskiy-nmGgyN9QBj3QT0dZR+AlfA@public.gmane.org>
2015-08-06 0:50 ` Wolfram Sang
2015-07-27 14:30 ` [PATCH v2 3/4] i2c: core: add and export of_get_i2c_adapter_by_node() interface Vladimir Zapolskiy
[not found] ` <1438007451-8553-4-git-send-email-vladimir_zapolskiy-nmGgyN9QBj3QT0dZR+AlfA@public.gmane.org>
2015-08-06 0:50 ` Wolfram Sang
2015-07-27 14:30 ` [PATCH v2 4/4] i2c: arb-gpio-challenge: use of_get_i2c_adapter_by_node interface Vladimir Zapolskiy
[not found] ` <1438007451-8553-5-git-send-email-vladimir_zapolskiy-nmGgyN9QBj3QT0dZR+AlfA@public.gmane.org>
2015-08-06 0:51 ` Wolfram Sang
2015-08-06 10:18 ` Vladimir Zapolskiy
2015-08-01 10:09 ` [PATCH v2 0/4] i2c: fix i2c adapter device driver user counter Wolfram Sang
2015-08-01 23:37 ` Vladimir Zapolskiy
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).