public inbox for kernel-janitors@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] thermal: tegra: delete unneeded of_node_put
@ 2017-07-15  8:42 Julia Lawall
       [not found] ` <1500108152-1812-1-git-send-email-Julia.Lawall-L2FTfq7BK8M@public.gmane.org>
  0 siblings, 1 reply; 5+ messages in thread
From: Julia Lawall @ 2017-07-15  8:42 UTC (permalink / raw)
  To: Zhang Rui
  Cc: kernel-janitors, Eduardo Valentin, Thierry Reding,
	Jonathan Hunter, linux-pm, linux-tegra, linux-kernel

Device node iterators perform an of_node_put on each iteration, so putting
an of_node_put before a continue results in a double put.

The semantic match that finds this problem is as follows
(http://coccinelle.lip6.fr):

// <smpl>
@@
expression e1;
local idexpression child;
iterator name for_each_child_of_node;
@@

 for_each_child_of_node(e1,child) {
   ... when != of_node_get(child)
*  of_node_put(child);
   ...
*  continue;
}
// </smpl>

Furthermore, the call to thermal_of_cooling_device_register immediately
calls __thermal_cooling_device_register with the same arguments.  The
latter function stores the device node argument, which is the second
argument of for_each_child_of_node, in the returned thermal_cooling_device
structure.  This returned structure is then stored in the cdev field of
stc.  Thus it seems that the second argument of for_each_child_of_node
escapes the scope of the for_each_child_of_node, so an explicit of_node_get
on success of thermal_of_cooling_device_register is also needed.

Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>

---
 drivers/thermal/tegra/soctherm.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/thermal/tegra/soctherm.c b/drivers/thermal/tegra/soctherm.c
index 7d2db23..10f4fdd 100644
--- a/drivers/thermal/tegra/soctherm.c
+++ b/drivers/thermal/tegra/soctherm.c
@@ -1014,7 +1014,6 @@ static void soctherm_init_hw_throt_cdev(struct platform_device *pdev)
 		tcd = thermal_of_cooling_device_register(np_stcc,
 							 (char *)name, ts,
 							 &throt_cooling_ops);
-		of_node_put(np_stcc);
 		if (IS_ERR_OR_NULL(tcd)) {
 			dev_err(dev,
 				"throttle-cfg: %s: failed to register cooling device\n",
@@ -1022,6 +1021,7 @@ static void soctherm_init_hw_throt_cdev(struct platform_device *pdev)
 			continue;
 		}
 
+		of_node_get(np_stcc);
 		stc->cdev = tcd;
 		stc->init = true;
 	}


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

* Re: [PATCH] thermal: tegra: delete unneeded of_node_put
       [not found] ` <1500108152-1812-1-git-send-email-Julia.Lawall-L2FTfq7BK8M@public.gmane.org>
@ 2017-07-17 13:47   ` Jon Hunter
       [not found]     ` <66e7906c-9472-4fcb-7c04-750bb27d3989-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
  0 siblings, 1 reply; 5+ messages in thread
From: Jon Hunter @ 2017-07-17 13:47 UTC (permalink / raw)
  To: Julia Lawall, Zhang Rui
  Cc: kernel-janitors-u79uwXL29TY76Z2rM5mHXA, Eduardo Valentin,
	Thierry Reding, linux-pm-u79uwXL29TY76Z2rM5mHXA,
	linux-tegra-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA


On 15/07/17 09:42, Julia Lawall wrote:
> Device node iterators perform an of_node_put on each iteration, so putting
> an of_node_put before a continue results in a double put.
> 
> The semantic match that finds this problem is as follows
> (http://coccinelle.lip6.fr):
> 
> // <smpl>
> @@
> expression e1;
> local idexpression child;
> iterator name for_each_child_of_node;
> @@
> 
>  for_each_child_of_node(e1,child) {
>    ... when != of_node_get(child)
> *  of_node_put(child);
>    ...
> *  continue;
> }
> // </smpl>
> 
> Furthermore, the call to thermal_of_cooling_device_register immediately
> calls __thermal_cooling_device_register with the same arguments.  The
> latter function stores the device node argument, which is the second
> argument of for_each_child_of_node, in the returned thermal_cooling_device
> structure.  This returned structure is then stored in the cdev field of
> stc.  Thus it seems that the second argument of for_each_child_of_node
> escapes the scope of the for_each_child_of_node, so an explicit of_node_get
> on success of thermal_of_cooling_device_register is also needed.
> 
> Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
> 
> ---
>  drivers/thermal/tegra/soctherm.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/thermal/tegra/soctherm.c b/drivers/thermal/tegra/soctherm.c
> index 7d2db23..10f4fdd 100644
> --- a/drivers/thermal/tegra/soctherm.c
> +++ b/drivers/thermal/tegra/soctherm.c
> @@ -1014,7 +1014,6 @@ static void soctherm_init_hw_throt_cdev(struct platform_device *pdev)
>  		tcd = thermal_of_cooling_device_register(np_stcc,
>  							 (char *)name, ts,
>  							 &throt_cooling_ops);
> -		of_node_put(np_stcc);
>  		if (IS_ERR_OR_NULL(tcd)) {
>  			dev_err(dev,
>  				"throttle-cfg: %s: failed to register cooling device\n",
> @@ -1022,6 +1021,7 @@ static void soctherm_init_hw_throt_cdev(struct platform_device *pdev)
>  			continue;
>  		}
>  
> +		of_node_get(np_stcc);
>  		stc->cdev = tcd;
>  		stc->init = true;
>  	}

Thanks for fixing this. However, I am wondering if it is better for the
'of_node_get' to be placed within the
thermal_of_cooling_device_register() function as it seems a bit odd if
the caller needs to know that this is being stored for later use.

Also, taking a quick look, I see a couple other drivers calling
thermal_of_cooling_device_register() and they are also not calling
of_node_get on success. So it maybe easier to fix placing it in the
thermal_of_cooling_device_register() function.

Cheers
Jon

-- 
nvpublic

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

* Re: [PATCH] thermal: tegra: delete unneeded of_node_put
       [not found]     ` <66e7906c-9472-4fcb-7c04-750bb27d3989-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
@ 2017-07-17 14:42       ` Julia Lawall
  2017-12-05  1:49         ` Eduardo Valentin
  0 siblings, 1 reply; 5+ messages in thread
From: Julia Lawall @ 2017-07-17 14:42 UTC (permalink / raw)
  To: Jon Hunter
  Cc: Zhang Rui, kernel-janitors-u79uwXL29TY76Z2rM5mHXA,
	Eduardo Valentin, Thierry Reding, linux-pm-u79uwXL29TY76Z2rM5mHXA,
	linux-tegra-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA



On Mon, 17 Jul 2017, Jon Hunter wrote:

>
> On 15/07/17 09:42, Julia Lawall wrote:
> > Device node iterators perform an of_node_put on each iteration, so putting
> > an of_node_put before a continue results in a double put.
> >
> > The semantic match that finds this problem is as follows
> > (http://coccinelle.lip6.fr):
> >
> > // <smpl>
> > @@
> > expression e1;
> > local idexpression child;
> > iterator name for_each_child_of_node;
> > @@
> >
> >  for_each_child_of_node(e1,child) {
> >    ... when != of_node_get(child)
> > *  of_node_put(child);
> >    ...
> > *  continue;
> > }
> > // </smpl>
> >
> > Furthermore, the call to thermal_of_cooling_device_register immediately
> > calls __thermal_cooling_device_register with the same arguments.  The
> > latter function stores the device node argument, which is the second
> > argument of for_each_child_of_node, in the returned thermal_cooling_device
> > structure.  This returned structure is then stored in the cdev field of
> > stc.  Thus it seems that the second argument of for_each_child_of_node
> > escapes the scope of the for_each_child_of_node, so an explicit of_node_get
> > on success of thermal_of_cooling_device_register is also needed.
> >
> > Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
> >
> > ---
> >  drivers/thermal/tegra/soctherm.c |    2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/thermal/tegra/soctherm.c b/drivers/thermal/tegra/soctherm.c
> > index 7d2db23..10f4fdd 100644
> > --- a/drivers/thermal/tegra/soctherm.c
> > +++ b/drivers/thermal/tegra/soctherm.c
> > @@ -1014,7 +1014,6 @@ static void soctherm_init_hw_throt_cdev(struct platform_device *pdev)
> >  		tcd = thermal_of_cooling_device_register(np_stcc,
> >  							 (char *)name, ts,
> >  							 &throt_cooling_ops);
> > -		of_node_put(np_stcc);
> >  		if (IS_ERR_OR_NULL(tcd)) {
> >  			dev_err(dev,
> >  				"throttle-cfg: %s: failed to register cooling device\n",
> > @@ -1022,6 +1021,7 @@ static void soctherm_init_hw_throt_cdev(struct platform_device *pdev)
> >  			continue;
> >  		}
> >
> > +		of_node_get(np_stcc);
> >  		stc->cdev = tcd;
> >  		stc->init = true;
> >  	}
>
> Thanks for fixing this. However, I am wondering if it is better for the
> 'of_node_get' to be placed within the
> thermal_of_cooling_device_register() function as it seems a bit odd if
> the caller needs to know that this is being stored for later use.
>
> Also, taking a quick look, I see a couple other drivers calling
> thermal_of_cooling_device_register() and they are also not calling
> of_node_get on success. So it maybe easier to fix placing it in the
> thermal_of_cooling_device_register() function.

I'm not an expert, but I had the impression that from some call sites, the
get would have been done already, because the argument is already stored
in some structure.  I can check more exhaustively.

julia


>
> Cheers
> Jon
>
> --
> nvpublic
> --
> To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>

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

* Re: [PATCH] thermal: tegra: delete unneeded of_node_put
  2017-07-17 14:42       ` Julia Lawall
@ 2017-12-05  1:49         ` Eduardo Valentin
       [not found]           ` <20171205014918.GB3536-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
  0 siblings, 1 reply; 5+ messages in thread
From: Eduardo Valentin @ 2017-12-05  1:49 UTC (permalink / raw)
  To: Julia Lawall
  Cc: Jon Hunter, Zhang Rui, kernel-janitors, Thierry Reding, linux-pm,
	linux-tegra, linux-kernel

On Mon, Jul 17, 2017 at 04:42:38PM +0200, Julia Lawall wrote:
> 
> 
> On Mon, 17 Jul 2017, Jon Hunter wrote:
> 
> >
> > On 15/07/17 09:42, Julia Lawall wrote:
> > > Device node iterators perform an of_node_put on each iteration, so putting
> > > an of_node_put before a continue results in a double put.
> > >
> > > The semantic match that finds this problem is as follows
> > > (http://coccinelle.lip6.fr):
> > >
> > > // <smpl>
> > > @@
> > > expression e1;
> > > local idexpression child;
> > > iterator name for_each_child_of_node;
> > > @@
> > >
> > >  for_each_child_of_node(e1,child) {
> > >    ... when != of_node_get(child)
> > > *  of_node_put(child);
> > >    ...
> > > *  continue;
> > > }
> > > // </smpl>
> > >
> > > Furthermore, the call to thermal_of_cooling_device_register immediately
> > > calls __thermal_cooling_device_register with the same arguments.  The
> > > latter function stores the device node argument, which is the second
> > > argument of for_each_child_of_node, in the returned thermal_cooling_device
> > > structure.  This returned structure is then stored in the cdev field of
> > > stc.  Thus it seems that the second argument of for_each_child_of_node
> > > escapes the scope of the for_each_child_of_node, so an explicit of_node_get
> > > on success of thermal_of_cooling_device_register is also needed.
> > >
> > > Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
> > >
> > > ---
> > >  drivers/thermal/tegra/soctherm.c |    2 +-
> > >  1 file changed, 1 insertion(+), 1 deletion(-)
> > >
> > > diff --git a/drivers/thermal/tegra/soctherm.c b/drivers/thermal/tegra/soctherm.c
> > > index 7d2db23..10f4fdd 100644
> > > --- a/drivers/thermal/tegra/soctherm.c
> > > +++ b/drivers/thermal/tegra/soctherm.c
> > > @@ -1014,7 +1014,6 @@ static void soctherm_init_hw_throt_cdev(struct platform_device *pdev)
> > >  		tcd = thermal_of_cooling_device_register(np_stcc,
> > >  							 (char *)name, ts,
> > >  							 &throt_cooling_ops);
> > > -		of_node_put(np_stcc);
> > >  		if (IS_ERR_OR_NULL(tcd)) {
> > >  			dev_err(dev,
> > >  				"throttle-cfg: %s: failed to register cooling device\n",
> > > @@ -1022,6 +1021,7 @@ static void soctherm_init_hw_throt_cdev(struct platform_device *pdev)
> > >  			continue;
> > >  		}
> > >
> > > +		of_node_get(np_stcc);
> > >  		stc->cdev = tcd;
> > >  		stc->init = true;
> > >  	}
> >
> > Thanks for fixing this. However, I am wondering if it is better for the
> > 'of_node_get' to be placed within the
> > thermal_of_cooling_device_register() function as it seems a bit odd if
> > the caller needs to know that this is being stored for later use.
> >
> > Also, taking a quick look, I see a couple other drivers calling
> > thermal_of_cooling_device_register() and they are also not calling
> > of_node_get on success. So it maybe easier to fix placing it in the
> > thermal_of_cooling_device_register() function.
> 
> I'm not an expert, but I had the impression that from some call sites, the
> get would have been done already, because the argument is already stored
> in some structure.  I can check more exhaustively.

Julia, I agree with Jon here. Better if fixed in the API itself. Are you
still planning on sending a fix for this?

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

* Re: [PATCH] thermal: tegra: delete unneeded of_node_put
       [not found]           ` <20171205014918.GB3536-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
@ 2017-12-05  6:17             ` Julia Lawall
  0 siblings, 0 replies; 5+ messages in thread
From: Julia Lawall @ 2017-12-05  6:17 UTC (permalink / raw)
  To: Eduardo Valentin
  Cc: Jon Hunter, Zhang Rui, kernel-janitors-u79uwXL29TY76Z2rM5mHXA,
	Thierry Reding, linux-pm-u79uwXL29TY76Z2rM5mHXA,
	linux-tegra-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA



On Mon, 4 Dec 2017, Eduardo Valentin wrote:

> On Mon, Jul 17, 2017 at 04:42:38PM +0200, Julia Lawall wrote:
> >
> >
> > On Mon, 17 Jul 2017, Jon Hunter wrote:
> >
> > >
> > > On 15/07/17 09:42, Julia Lawall wrote:
> > > > Device node iterators perform an of_node_put on each iteration, so putting
> > > > an of_node_put before a continue results in a double put.
> > > >
> > > > The semantic match that finds this problem is as follows
> > > > (http://coccinelle.lip6.fr):
> > > >
> > > > // <smpl>
> > > > @@
> > > > expression e1;
> > > > local idexpression child;
> > > > iterator name for_each_child_of_node;
> > > > @@
> > > >
> > > >  for_each_child_of_node(e1,child) {
> > > >    ... when != of_node_get(child)
> > > > *  of_node_put(child);
> > > >    ...
> > > > *  continue;
> > > > }
> > > > // </smpl>
> > > >
> > > > Furthermore, the call to thermal_of_cooling_device_register immediately
> > > > calls __thermal_cooling_device_register with the same arguments.  The
> > > > latter function stores the device node argument, which is the second
> > > > argument of for_each_child_of_node, in the returned thermal_cooling_device
> > > > structure.  This returned structure is then stored in the cdev field of
> > > > stc.  Thus it seems that the second argument of for_each_child_of_node
> > > > escapes the scope of the for_each_child_of_node, so an explicit of_node_get
> > > > on success of thermal_of_cooling_device_register is also needed.
> > > >
> > > > Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
> > > >
> > > > ---
> > > >  drivers/thermal/tegra/soctherm.c |    2 +-
> > > >  1 file changed, 1 insertion(+), 1 deletion(-)
> > > >
> > > > diff --git a/drivers/thermal/tegra/soctherm.c b/drivers/thermal/tegra/soctherm.c
> > > > index 7d2db23..10f4fdd 100644
> > > > --- a/drivers/thermal/tegra/soctherm.c
> > > > +++ b/drivers/thermal/tegra/soctherm.c
> > > > @@ -1014,7 +1014,6 @@ static void soctherm_init_hw_throt_cdev(struct platform_device *pdev)
> > > >  		tcd = thermal_of_cooling_device_register(np_stcc,
> > > >  							 (char *)name, ts,
> > > >  							 &throt_cooling_ops);
> > > > -		of_node_put(np_stcc);
> > > >  		if (IS_ERR_OR_NULL(tcd)) {
> > > >  			dev_err(dev,
> > > >  				"throttle-cfg: %s: failed to register cooling device\n",
> > > > @@ -1022,6 +1021,7 @@ static void soctherm_init_hw_throt_cdev(struct platform_device *pdev)
> > > >  			continue;
> > > >  		}
> > > >
> > > > +		of_node_get(np_stcc);
> > > >  		stc->cdev = tcd;
> > > >  		stc->init = true;
> > > >  	}
> > >
> > > Thanks for fixing this. However, I am wondering if it is better for the
> > > 'of_node_get' to be placed within the
> > > thermal_of_cooling_device_register() function as it seems a bit odd if
> > > the caller needs to know that this is being stored for later use.
> > >
> > > Also, taking a quick look, I see a couple other drivers calling
> > > thermal_of_cooling_device_register() and they are also not calling
> > > of_node_get on success. So it maybe easier to fix placing it in the
> > > thermal_of_cooling_device_register() function.
> >
> > I'm not an expert, but I had the impression that from some call sites, the
> > get would have been done already, because the argument is already stored
> > in some structure.  I can check more exhaustively.
>
> Julia, I agree with Jon here. Better if fixed in the API itself. Are you
> still planning on sending a fix for this?

This has fallen off my stack, and I'mnot sure that Ican get to it in the
short term.

julia

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

end of thread, other threads:[~2017-12-05  6:17 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-07-15  8:42 [PATCH] thermal: tegra: delete unneeded of_node_put Julia Lawall
     [not found] ` <1500108152-1812-1-git-send-email-Julia.Lawall-L2FTfq7BK8M@public.gmane.org>
2017-07-17 13:47   ` Jon Hunter
     [not found]     ` <66e7906c-9472-4fcb-7c04-750bb27d3989-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2017-07-17 14:42       ` Julia Lawall
2017-12-05  1:49         ` Eduardo Valentin
     [not found]           ` <20171205014918.GB3536-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2017-12-05  6:17             ` Julia Lawall

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox