All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] i2c: i2c-mux-gpmux: Add of_node_put() when breaking out of loop
@ 2022-07-21  8:12 Liang He
  2022-07-21  9:20 ` Peter Rosin
  0 siblings, 1 reply; 3+ messages in thread
From: Liang He @ 2022-07-21  8:12 UTC (permalink / raw)
  To: peda, linux-i2c, windhl

In i2c_mux_probe(), we should call of_node_put() when breaking out
of for_each_child_of_node() which will automatically increase and
decrease the refcount.

Fixes: ac8498f0ce53 ("i2c: i2c-mux-gpmux: new driver")
Signed-off-by: Liang He <windhl@126.com>
---
 drivers/i2c/muxes/i2c-mux-gpmux.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/i2c/muxes/i2c-mux-gpmux.c b/drivers/i2c/muxes/i2c-mux-gpmux.c
index d3acd8d66c32..30ab2fe88c8d 100644
--- a/drivers/i2c/muxes/i2c-mux-gpmux.c
+++ b/drivers/i2c/muxes/i2c-mux-gpmux.c
@@ -115,6 +115,7 @@ static int i2c_mux_probe(struct platform_device *pdev)
 		if (ret < 0) {
 			dev_err(dev, "no reg property for node '%pOFn'\n",
 				child);
+			of_node_put(child);
 			goto err_children;
 		}
 
-- 
2.25.1


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

* Re: [PATCH] i2c: i2c-mux-gpmux: Add of_node_put() when breaking out of loop
  2022-07-21  8:12 [PATCH] i2c: i2c-mux-gpmux: Add of_node_put() when breaking out of loop Liang He
@ 2022-07-21  9:20 ` Peter Rosin
  2022-07-22  1:14   ` Liang He
  0 siblings, 1 reply; 3+ messages in thread
From: Peter Rosin @ 2022-07-21  9:20 UTC (permalink / raw)
  To: Liang He, linux-i2c

Hi!

2022-07-21 at 10:12, Liang He wrote:
> In i2c_mux_probe(), we should call of_node_put() when breaking out
> of for_each_child_of_node() which will automatically increase and
> decrease the refcount.
> 
> Fixes: ac8498f0ce53 ("i2c: i2c-mux-gpmux: new driver")
> Signed-off-by: Liang He <windhl@126.com>
> ---
>  drivers/i2c/muxes/i2c-mux-gpmux.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/i2c/muxes/i2c-mux-gpmux.c b/drivers/i2c/muxes/i2c-mux-gpmux.c
> index d3acd8d66c32..30ab2fe88c8d 100644
> --- a/drivers/i2c/muxes/i2c-mux-gpmux.c
> +++ b/drivers/i2c/muxes/i2c-mux-gpmux.c
> @@ -115,6 +115,7 @@ static int i2c_mux_probe(struct platform_device *pdev)
>  		if (ret < 0) {
>  			dev_err(dev, "no reg property for node '%pOFn'\n",
>  				child);
> +			of_node_put(child);
>  			goto err_children;
>  		}
>  

Right, but this is obviously incomplete. What about the other two branches
in that loop that breaks out?

Much better to have the missing of_node_put(child) statement below the
err_children: label (i.e. before i2c_mux_del_adapters) so that it is not
forgotten in any code flow. child cannot be uninitialized at that point
and if it happens to be NULL, of_node_put will be a nop. So that's safe.

Cheers,
Peter

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

* Re:Re: [PATCH] i2c: i2c-mux-gpmux: Add of_node_put() when breaking out of loop
  2022-07-21  9:20 ` Peter Rosin
@ 2022-07-22  1:14   ` Liang He
  0 siblings, 0 replies; 3+ messages in thread
From: Liang He @ 2022-07-22  1:14 UTC (permalink / raw)
  To: Peter Rosin; +Cc: linux-i2c


At 2022-07-21 17:20:56, "Peter Rosin" <peda@axentia.se> wrote:
>Hi!
>
>2022-07-21 at 10:12, Liang He wrote:
>> In i2c_mux_probe(), we should call of_node_put() when breaking out
>> of for_each_child_of_node() which will automatically increase and
>> decrease the refcount.
>> 
>> Fixes: ac8498f0ce53 ("i2c: i2c-mux-gpmux: new driver")
>> Signed-off-by: Liang He <windhl@126.com>
>> ---
>>  drivers/i2c/muxes/i2c-mux-gpmux.c | 1 +
>>  1 file changed, 1 insertion(+)
>> 
>> diff --git a/drivers/i2c/muxes/i2c-mux-gpmux.c b/drivers/i2c/muxes/i2c-mux-gpmux.c
>> index d3acd8d66c32..30ab2fe88c8d 100644
>> --- a/drivers/i2c/muxes/i2c-mux-gpmux.c
>> +++ b/drivers/i2c/muxes/i2c-mux-gpmux.c
>> @@ -115,6 +115,7 @@ static int i2c_mux_probe(struct platform_device *pdev)
>>  		if (ret < 0) {
>>  			dev_err(dev, "no reg property for node '%pOFn'\n",
>>  				child);
>> +			of_node_put(child);
>>  			goto err_children;
>>  		}
>>  
>
>Right, but this is obviously incomplete. What about the other two branches
>in that loop that breaks out?
>
>Much better to have the missing of_node_put(child) statement below the
>err_children: label (i.e. before i2c_mux_del_adapters) so that it is not
>forgotten in any code flow. child cannot be uninitialized at that point
>and if it happens to be NULL, of_node_put will be a nop. So that's safe.
>
>Cheers,
>Peter

Thanks, Peter,

I have forgotten add of_node_put() in other fail path.
But your advice is better, I will send a new version soon!

Thanks again,

Liang

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

end of thread, other threads:[~2022-07-22  1:14 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-21  8:12 [PATCH] i2c: i2c-mux-gpmux: Add of_node_put() when breaking out of loop Liang He
2022-07-21  9:20 ` Peter Rosin
2022-07-22  1:14   ` Liang He

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.