All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] i2c: core: decrease reference count of device node in i2c_unregister_device
@ 2017-11-27  7:06 ` Lixin Wang
  0 siblings, 0 replies; 5+ messages in thread
From: Lixin Wang @ 2017-11-27  7:06 UTC (permalink / raw)
  To: Wolfram Sang; +Cc: linux-i2c, linux-kernel, Lixin Wang

Reference count of device node was increased in of_i2c_register_device,
but without decreasing it in i2c_unregister_device. Then the dynamically
added device node will never be released.
Fix this by adding the of_node_put.

Signed-off-by: Lixin Wang <alan.1.wang@nokia-sbell.com>
---
 drivers/i2c/i2c-core-base.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
index 56e4658..b76adf9 100644
--- a/drivers/i2c/i2c-core-base.c
+++ b/drivers/i2c/i2c-core-base.c
@@ -808,8 +808,10 @@ EXPORT_SYMBOL_GPL(i2c_new_device);
  */
 void i2c_unregister_device(struct i2c_client *client)
 {
-	if (client->dev.of_node)
+	if (client->dev.of_node) {
 		of_node_clear_flag(client->dev.of_node, OF_POPULATED);
+		of_node_put(client->dev.of_node);
+	}
 	if (ACPI_COMPANION(&client->dev))
 		acpi_device_clear_enumerated(ACPI_COMPANION(&client->dev));
 	device_unregister(&client->dev);
-- 
2.6.2

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

* [PATCH] i2c: core: decrease reference count of device node in i2c_unregister_device
@ 2017-11-27  7:06 ` Lixin Wang
  0 siblings, 0 replies; 5+ messages in thread
From: Lixin Wang @ 2017-11-27  7:06 UTC (permalink / raw)
  To: Wolfram Sang; +Cc: linux-i2c, linux-kernel, Lixin Wang

Reference count of device node was increased in of_i2c_register_device,
but without decreasing it in i2c_unregister_device. Then the dynamically
added device node will never be released.
Fix this by adding the of_node_put.

Signed-off-by: Lixin Wang <alan.1.wang@nokia-sbell.com>
---
 drivers/i2c/i2c-core-base.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
index 56e4658..b76adf9 100644
--- a/drivers/i2c/i2c-core-base.c
+++ b/drivers/i2c/i2c-core-base.c
@@ -808,8 +808,10 @@ EXPORT_SYMBOL_GPL(i2c_new_device);
  */
 void i2c_unregister_device(struct i2c_client *client)
 {
-	if (client->dev.of_node)
+	if (client->dev.of_node) {
 		of_node_clear_flag(client->dev.of_node, OF_POPULATED);
+		of_node_put(client->dev.of_node);
+	}
 	if (ACPI_COMPANION(&client->dev))
 		acpi_device_clear_enumerated(ACPI_COMPANION(&client->dev));
 	device_unregister(&client->dev);
-- 
2.6.2

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

* Re: [PATCH] i2c: core: decrease reference count of device node in i2c_unregister_device
  2017-11-27  7:06 ` Lixin Wang
  (?)
@ 2017-11-27 18:21 ` Wolfram Sang
  2017-11-29  8:06   ` Wang, Alan 1. (NSB - CN/Hangzhou)
  -1 siblings, 1 reply; 5+ messages in thread
From: Wolfram Sang @ 2017-11-27 18:21 UTC (permalink / raw)
  To: Lixin Wang; +Cc: linux-i2c, linux-kernel

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

On Mon, Nov 27, 2017 at 03:06:55PM +0800, Lixin Wang wrote:
> Reference count of device node was increased in of_i2c_register_device,
> but without decreasing it in i2c_unregister_device. 

Huh, there is an of_node_put(bus) in of_i2c_register_device?

> Then the dynamically
> added device node will never be released.

Strange. Can you provide your test case, please?


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* RE: [PATCH] i2c: core: decrease reference count of device node in i2c_unregister_device
  2017-11-27 18:21 ` Wolfram Sang
@ 2017-11-29  8:06   ` Wang, Alan 1. (NSB - CN/Hangzhou)
  0 siblings, 0 replies; 5+ messages in thread
From: Wang, Alan 1. (NSB - CN/Hangzhou) @ 2017-11-29  8:06 UTC (permalink / raw)
  To: Wolfram Sang; +Cc: linux-i2c, linux-kernel

Hi Wolfram,

In my understand, the of_node_put(bus) is to of_get_child_by_name((adap->dev.of_node, "i2c-bus") or of_node_get(adap->dev.of_node).

What I said is the children of "bus" increased by "info.of_node = of_node_get(node)" in function of_i2c_register_device.

My description in last mail maybe not properly, I think all the nodes accessed by of_i2c_register_device shall not be decreased, not only the dynamically added ones. 

In my case, the SFP devices as i2c clients on one board are connected to the bus through i2c mux.
When plugin the board, all the related nodes are dynamically allocated and added into the device tree.
Then the probe function calls of_i2c_register_devices, in which the reference count increased by " info.of_node = of_node_get(node)".
When plug out the board, because the reference count of those nodes are not decreased down to 0, the memory of the nodes and their properties are not released.
New memory will be allocated but not released in the next plugin and plug out looping test. 

Best Regards,
Lixin Wang

> -----Original Message-----
> From: Wolfram Sang [mailto:wsa@the-dreams.de]
> Sent: Tuesday, November 28, 2017 2:22 AM
> To: Wang, Alan 1. (NSB - CN/Hangzhou) <alan.1.wang@nokia-sbell.com>
> Cc: linux-i2c@vger.kernel.org; linux-kernel@vger.kernel.org
> Subject: Re: [PATCH] i2c: core: decrease reference count of device node in
> i2c_unregister_device
> 
> On Mon, Nov 27, 2017 at 03:06:55PM +0800, Lixin Wang wrote:
> > Reference count of device node was increased in
> > of_i2c_register_device, but without decreasing it in i2c_unregister_device.
> 
> Huh, there is an of_node_put(bus) in of_i2c_register_device?
> 
> > Then the dynamically
> > added device node will never be released.
> 
> Strange. Can you provide your test case, please?

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

* Re: i2c: core: decrease reference count of device node in i2c_unregister_device
  2017-11-27  7:06 ` Lixin Wang
  (?)
  (?)
@ 2018-01-15 23:02 ` Wolfram Sang
  -1 siblings, 0 replies; 5+ messages in thread
From: Wolfram Sang @ 2018-01-15 23:02 UTC (permalink / raw)
  To: Lixin Wang; +Cc: linux-i2c, linux-kernel

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

On Mon, Nov 27, 2017 at 03:06:55PM +0800, Lixin Wang wrote:
> Reference count of device node was increased in of_i2c_register_device,
> but without decreasing it in i2c_unregister_device. Then the dynamically
> added device node will never be released.
> Fix this by adding the of_node_put.
> 
> Signed-off-by: Lixin Wang <alan.1.wang@nokia-sbell.com>

Yes you are right! In my previous review, I mixed up
of_i2c_register_devices (with plural 's') with of_i2c_register_device
(without plural 's'). I could now verify your findings by rebinding an
adapter which had DT bindings for clients attached. With every rebind
cycle, the refcount for the client increased.

I did some rebasing, because your patch didn't apply to a v4.15
codebase. Now, applied to for-current, thanks!


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

end of thread, other threads:[~2018-01-15 23:02 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-27  7:06 [PATCH] i2c: core: decrease reference count of device node in i2c_unregister_device Lixin Wang
2017-11-27  7:06 ` Lixin Wang
2017-11-27 18:21 ` Wolfram Sang
2017-11-29  8:06   ` Wang, Alan 1. (NSB - CN/Hangzhou)
2018-01-15 23:02 ` Wolfram Sang

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.