kernel-janitors.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/5] add missing of_node_put
@ 2015-10-10 12:30 Julia Lawall
  2015-10-10 12:30 ` [PATCH 1/5] backlight: 88pm860x_bl: " Julia Lawall
                   ` (7 more replies)
  0 siblings, 8 replies; 66+ messages in thread
From: Julia Lawall @ 2015-10-10 12:30 UTC (permalink / raw)
  To: linux-arm-kernel

for_each_child_of_node performs an of_node_get on each iteration, so
a break out of the loop requires an of_node_put.

The complete semantic patch that fixes this problem is
(http://coccinelle.lip6.fr):

// <smpl>
@@
expression root,e;
local idexpression child;
iterator name for_each_child_of_node;
@@

 for_each_child_of_node(root, child) {
   ... when != of_node_put(child)
       when != e = child
+  of_node_put(child);
?  break;
   ...
}
... when != child

@@
expression root,e;
local idexpression child;
@@

 for_each_child_of_node(root, child) {
   ... when != of_node_put(child)
       when != e = child
(
   return child;
|
+  of_node_put(child);
?  return ...;
)
   ...
 }
// </smpl>

---

 arch/arm/kernel/devtree.c             |    1 +
 arch/arm/mach-shmobile/pm-rmobile.c   |    4 +++-
 drivers/power/charger-manager.c       |    4 +++-
 drivers/regulator/of_regulator.c      |    1 +
 drivers/video/backlight/88pm860x_bl.c |    1 +
 5 files changed, 9 insertions(+), 2 deletions(-)

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

* [PATCH 1/5] backlight: 88pm860x_bl: add missing of_node_put
  2015-10-10 12:30 [PATCH 0/5] add missing of_node_put Julia Lawall
@ 2015-10-10 12:30 ` Julia Lawall
  2015-10-13  8:15   ` Lee Jones
  2015-10-10 12:30 ` [PATCH 2/5] power_supply: charger-manager: " Julia Lawall
                   ` (6 subsequent siblings)
  7 siblings, 1 reply; 66+ messages in thread
From: Julia Lawall @ 2015-10-10 12:30 UTC (permalink / raw)
  To: Jingoo Han
  Cc: kernel-janitors, Lee Jones, Jean-Christophe Plagniol-Villard,
	Tomi Valkeinen, linux-fbdev, linux-kernel,
	Russell King - ARM Linux, Thomas Petazzoni, Andrew Lunn,
	Bjorn Helgaas, Jason Cooper

for_each_child_of_node performs an of_node_get on each iteration, so
a break out of the loop requires an of_node_put.

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

// <smpl>
@@
expression root,e;
local idexpression child;
iterator name for_each_child_of_node;
@@

 for_each_child_of_node(root, child) {
   ... when != of_node_put(child)
       when != e = child
+  of_node_put(child);
?  break;
   ...
}
... when != child
// </smpl>

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

---
 drivers/video/backlight/88pm860x_bl.c |    1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/video/backlight/88pm860x_bl.c b/drivers/video/backlight/88pm860x_bl.c
index 2da5862..6d8dc2c 100644
--- a/drivers/video/backlight/88pm860x_bl.c
+++ b/drivers/video/backlight/88pm860x_bl.c
@@ -180,6 +180,7 @@ static int pm860x_backlight_dt_init(struct platform_device *pdev,
 			data->iset = PM8606_WLED_CURRENT(iset);
 			of_property_read_u32(np, "marvell,88pm860x-pwm",
 					     &data->pwm);
+			of_node_put(np);
 			break;
 		}
 	}


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

* [PATCH 2/5] power_supply: charger-manager: add missing of_node_put
  2015-10-10 12:30 [PATCH 0/5] add missing of_node_put Julia Lawall
  2015-10-10 12:30 ` [PATCH 1/5] backlight: 88pm860x_bl: " Julia Lawall
@ 2015-10-10 12:30 ` Julia Lawall
  2015-10-12  2:20   ` Krzysztof Kozlowski
  2015-10-15  8:56   ` Sebastian Reichel
  2015-10-10 12:30 ` [PATCH 3/5] ARM: shmobile: R-Mobile: " Julia Lawall
                   ` (5 subsequent siblings)
  7 siblings, 2 replies; 66+ messages in thread
From: Julia Lawall @ 2015-10-10 12:30 UTC (permalink / raw)
  To: Sebastian Reichel
  Cc: kernel-janitors, Dmitry Eremin-Solenikov, David Woodhouse,
	linux-pm, linux-kernel, Russell King - ARM Linux,
	Thomas Petazzoni, Andrew Lunn, Bjorn Helgaas, Jason Cooper

for_each_child_of_node performs an of_node_get on each iteration, so
a break out of the loop requires an of_node_put.

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

// <smpl>
@@
expression root,e;
local idexpression child;
@@

 for_each_child_of_node(root, child) {
   ... when != of_node_put(child)
       when != e = child
(
   return child;
|
+  of_node_put(child);
?  return ...;
)
   ...
 }
// </smpl>

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

---
 drivers/power/charger-manager.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/power/charger-manager.c b/drivers/power/charger-manager.c
index 907293e..1ea5d1a 100644
--- a/drivers/power/charger-manager.c
+++ b/drivers/power/charger-manager.c
@@ -1581,8 +1581,10 @@ static struct charger_desc *of_cm_parse_desc(struct device *dev)
 				cables = devm_kzalloc(dev, sizeof(*cables)
 						* chg_regs->num_cables,
 						GFP_KERNEL);
-				if (!cables)
+				if (!cables) {
+					of_node_put(child);
 					return ERR_PTR(-ENOMEM);
+				}
 
 				chg_regs->cables = cables;
 


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

* [PATCH 3/5] ARM: shmobile: R-Mobile: add missing of_node_put
  2015-10-10 12:30 [PATCH 0/5] add missing of_node_put Julia Lawall
  2015-10-10 12:30 ` [PATCH 1/5] backlight: 88pm860x_bl: " Julia Lawall
  2015-10-10 12:30 ` [PATCH 2/5] power_supply: charger-manager: " Julia Lawall
@ 2015-10-10 12:30 ` Julia Lawall
  2015-10-12  0:16   ` Simon Horman
  2015-10-12  7:18   ` Geert Uytterhoeven
  2015-10-10 12:30 ` [PATCH 4/5] regulator: of: " Julia Lawall
                   ` (4 subsequent siblings)
  7 siblings, 2 replies; 66+ messages in thread
From: Julia Lawall @ 2015-10-10 12:30 UTC (permalink / raw)
  To: linux-arm-kernel

for_each_child_of_node performs an of_node_get on each iteration, so
a break out of the loop requires an of_node_put.

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

// <smpl>
@@
expression root,e;
local idexpression child;
@@

 for_each_child_of_node(root, child) {
   ... when != of_node_put(child)
       when != e = child
(
   return child;
|
+  of_node_put(child);
?  return ...;
)
   ...
 }
// </smpl>

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

---
 arch/arm/mach-shmobile/pm-rmobile.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/arch/arm/mach-shmobile/pm-rmobile.c b/arch/arm/mach-shmobile/pm-rmobile.c
index 89068c8..46d0a1d 100644
--- a/arch/arm/mach-shmobile/pm-rmobile.c
+++ b/arch/arm/mach-shmobile/pm-rmobile.c
@@ -313,8 +313,10 @@ static int __init rmobile_add_pm_domains(void __iomem *base,
 		}
 
 		pd = kzalloc(sizeof(*pd), GFP_KERNEL);
-		if (!pd)
+		if (!pd) {
+			of_node_put(np);
 			return -ENOMEM;
+		}
 
 		pd->genpd.name = np->name;
 		pd->base = base;


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

* [PATCH 4/5] regulator: of: add missing of_node_put
  2015-10-10 12:30 [PATCH 0/5] add missing of_node_put Julia Lawall
                   ` (2 preceding siblings ...)
  2015-10-10 12:30 ` [PATCH 3/5] ARM: shmobile: R-Mobile: " Julia Lawall
@ 2015-10-10 12:30 ` Julia Lawall
  2015-10-12  0:33   ` Krzysztof Kozlowski
  2018-02-12 12:09   ` Applied "regulator: of: Add a missing 'of_node_put()' in an error handling path of 'of_regulator_mat Mark Brown
  2015-10-10 12:30 ` [PATCH 5/5] arm: add missing of_node_put Julia Lawall
                   ` (3 subsequent siblings)
  7 siblings, 2 replies; 66+ messages in thread
From: Julia Lawall @ 2015-10-10 12:30 UTC (permalink / raw)
  To: Liam Girdwood
  Cc: kernel-janitors, Mark Brown, linux-kernel,
	Russell King - ARM Linux, Thomas Petazzoni, Andrew Lunn,
	Bjorn Helgaas, Jason Cooper

for_each_child_of_node performs an of_node_get on each iteration, so
a break out of the loop requires an of_node_put.

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

// <smpl>
@@
expression root,e;
local idexpression child;
@@

 for_each_child_of_node(root, child) {
   ... when != of_node_put(child)
       when != e = child
(
   return child;
|
+  of_node_put(child);
?  return ...;
)
   ...
 }
// </smpl>

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

---
 drivers/regulator/of_regulator.c |    1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/regulator/of_regulator.c b/drivers/regulator/of_regulator.c
index 499e437..f9d77b4 100644
--- a/drivers/regulator/of_regulator.c
+++ b/drivers/regulator/of_regulator.c
@@ -274,6 +274,7 @@ int of_regulator_match(struct device *dev, struct device_node *node,
 				dev_err(dev,
 					"failed to parse DT for regulator %s\n",
 					child->name);
+				of_node_put(child);
 				return -EINVAL;
 			}
 			match->of_node = of_node_get(child);


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

* [PATCH 5/5] arm: add missing of_node_put
  2015-10-10 12:30 [PATCH 0/5] add missing of_node_put Julia Lawall
                   ` (3 preceding siblings ...)
  2015-10-10 12:30 ` [PATCH 4/5] regulator: of: " Julia Lawall
@ 2015-10-10 12:30 ` Julia Lawall
  2015-10-10 21:02   ` Arnd Bergmann
  2015-10-21 20:41 ` [PATCH 0/5] " Julia Lawall
                   ` (2 subsequent siblings)
  7 siblings, 1 reply; 66+ messages in thread
From: Julia Lawall @ 2015-10-10 12:30 UTC (permalink / raw)
  To: linux-arm-kernel

for_each_child_of_node performs an of_node_get on each iteration, so
a break out of the loop requires an of_node_put.

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

// <smpl>
@@
expression root,e;
local idexpression child;
iterator name for_each_child_of_node;
@@

 for_each_child_of_node(root, child) {
   ... when != of_node_put(child)
       when != e = child
+  of_node_put(child);
?  break;
   ...
}
... when != child
// </smpl>

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

---
 arch/arm/kernel/devtree.c |    1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm/kernel/devtree.c b/arch/arm/kernel/devtree.c
index 11c54de..432ff34 100644
--- a/arch/arm/kernel/devtree.c
+++ b/arch/arm/kernel/devtree.c
@@ -143,6 +143,7 @@ void __init arm_dt_init_cpu_maps(void)
 					       "max cores %u, capping them\n",
 					       cpuidx, nr_cpu_ids)) {
 			cpuidx = nr_cpu_ids;
+			of_node_put(cpu);
 			break;
 		}
 


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

* Re: [PATCH 5/5] arm: add missing of_node_put
  2015-10-10 12:30 ` [PATCH 5/5] arm: add missing of_node_put Julia Lawall
@ 2015-10-10 21:02   ` Arnd Bergmann
  2015-10-10 21:08     ` Thomas Petazzoni
  2015-10-10 21:10     ` Julia Lawall
  0 siblings, 2 replies; 66+ messages in thread
From: Arnd Bergmann @ 2015-10-10 21:02 UTC (permalink / raw)
  To: linux-arm-kernel

On Saturday 10 October 2015 14:30:54 Julia Lawall wrote:
> diff --git a/arch/arm/kernel/devtree.c b/arch/arm/kernel/devtree.c
> index 11c54de..432ff34 100644
> --- a/arch/arm/kernel/devtree.c
> +++ b/arch/arm/kernel/devtree.c
> @@ -143,6 +143,7 @@ void __init arm_dt_init_cpu_maps(void)
>                                                "max cores %u, capping them\n",
>                                                cpuidx, nr_cpu_ids)) {
>                         cpuidx = nr_cpu_ids;
> +                       of_node_put(cpu);
>                         break;
>                 }
> 

The same for_each_child_of_node() loop has three 'return' statements'
aside from the 'break' statement here. I think you should change your
semantic patch to cover both cases.

	Arnd

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

* Re: [PATCH 5/5] arm: add missing of_node_put
  2015-10-10 21:02   ` Arnd Bergmann
@ 2015-10-10 21:08     ` Thomas Petazzoni
  2015-10-10 21:12       ` Julia Lawall
  2015-10-10 21:10     ` Julia Lawall
  1 sibling, 1 reply; 66+ messages in thread
From: Thomas Petazzoni @ 2015-10-10 21:08 UTC (permalink / raw)
  To: linux-arm-kernel

Arnd,

On Sat, 10 Oct 2015 23:02:15 +0200, Arnd Bergmann wrote:

> The same for_each_child_of_node() loop has three 'return' statements'
> aside from the 'break' statement here. I think you should change your
> semantic patch to cover both cases.

I think Julia's semantic patch covers both cases, but only the cases
where there is one break or return (though I have essentially zero
Coccinelle knowledge, this is all based on guessing looking at the
semantic patch in the cover letter).

Thomas
-- 
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com

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

* Re: [PATCH 5/5] arm: add missing of_node_put
  2015-10-10 21:02   ` Arnd Bergmann
  2015-10-10 21:08     ` Thomas Petazzoni
@ 2015-10-10 21:10     ` Julia Lawall
  2015-10-10 21:15       ` Arnd Bergmann
  1 sibling, 1 reply; 66+ messages in thread
From: Julia Lawall @ 2015-10-10 21:10 UTC (permalink / raw)
  To: linux-arm-kernel

On Sat, 10 Oct 2015, Arnd Bergmann wrote:

> On Saturday 10 October 2015 14:30:54 Julia Lawall wrote:
> > diff --git a/arch/arm/kernel/devtree.c b/arch/arm/kernel/devtree.c
> > index 11c54de..432ff34 100644
> > --- a/arch/arm/kernel/devtree.c
> > +++ b/arch/arm/kernel/devtree.c
> > @@ -143,6 +143,7 @@ void __init arm_dt_init_cpu_maps(void)
> >                                                "max cores %u, capping them\n",
> >                                                cpuidx, nr_cpu_ids)) {
> >                         cpuidx = nr_cpu_ids;
> > +                       of_node_put(cpu);
> >                         break;
> >                 }
> > 
> 
> The same for_each_child_of_node() loop has three 'return' statements'
> aside from the 'break' statement here. I think you should change your
> semantic patch to cover both cases.

It was intended to, but it seems that it's not working on the case where 
there is no argument to return.

In any case, it's an opportunity to ask a question.  Would one want a 
of_node_put in front of every return, or should the returns become gotos, 
to a single of_node_put after the current end of the function?

julia

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

* Re: [PATCH 5/5] arm: add missing of_node_put
  2015-10-10 21:08     ` Thomas Petazzoni
@ 2015-10-10 21:12       ` Julia Lawall
  0 siblings, 0 replies; 66+ messages in thread
From: Julia Lawall @ 2015-10-10 21:12 UTC (permalink / raw)
  To: linux-arm-kernel

On Sat, 10 Oct 2015, Thomas Petazzoni wrote:

> Arnd,
> 
> On Sat, 10 Oct 2015 23:02:15 +0200, Arnd Bergmann wrote:
> 
> > The same for_each_child_of_node() loop has three 'return' statements'
> > aside from the 'break' statement here. I think you should change your
> > semantic patch to cover both cases.
> 
> I think Julia's semantic patch covers both cases, but only the cases
> where there is one break or return (though I have essentially zero
> Coccinelle knowledge, this is all based on guessing looking at the
> semantic patch in the cover letter).

Normally, it should be OK with lots of returns.  And contrary to my 
previous email, even with return;.  Will check on it.

julia

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

* Re: [PATCH 5/5] arm: add missing of_node_put
  2015-10-10 21:10     ` Julia Lawall
@ 2015-10-10 21:15       ` Arnd Bergmann
  2015-10-10 21:41         ` [PATCH 5/5 v2] " Julia Lawall
  0 siblings, 1 reply; 66+ messages in thread
From: Arnd Bergmann @ 2015-10-10 21:15 UTC (permalink / raw)
  To: linux-arm-kernel

On Saturday 10 October 2015 23:10:06 Julia Lawall wrote:
> On Sat, 10 Oct 2015, Arnd Bergmann wrote:
> 
> > On Saturday 10 October 2015 14:30:54 Julia Lawall wrote:
> > > diff --git a/arch/arm/kernel/devtree.c b/arch/arm/kernel/devtree.c
> > > index 11c54de..432ff34 100644
> > > --- a/arch/arm/kernel/devtree.c
> > > +++ b/arch/arm/kernel/devtree.c
> > > @@ -143,6 +143,7 @@ void __init arm_dt_init_cpu_maps(void)
> > >                                                "max cores %u, capping them\n",
> > >                                                cpuidx, nr_cpu_ids)) {
> > >                         cpuidx = nr_cpu_ids;
> > > +                       of_node_put(cpu);
> > >                         break;
> > >                 }
> > > 
> > 
> > The same for_each_child_of_node() loop has three 'return' statements'
> > aside from the 'break' statement here. I think you should change your
> > semantic patch to cover both cases.
> 
> It was intended to,

Ok, I saw that just after replying...

> but it seems that it's not working on the case where 
> there is no argument to return.

> In any case, it's an opportunity to ask a question.  Would one want a 
> of_node_put in front of every return, or should the returns become gotos, 
> to a single of_node_put after the current end of the function?

The two styles that I see in code I consider particularly clean are:

- have only one return statement in the function and use goto for
  error handling

- avoid the goto and have the early return.

Mixing the two tends to make the function less readable, so I'd only
change it to use gotos if it can be done nicely for all cases.

	Arnd

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

* [PATCH 5/5 v2] arm: add missing of_node_put
  2015-10-10 21:15       ` Arnd Bergmann
@ 2015-10-10 21:41         ` Julia Lawall
  0 siblings, 0 replies; 66+ messages in thread
From: Julia Lawall @ 2015-10-10 21:41 UTC (permalink / raw)
  To: linux-arm-kernel

for_each_child_of_node performs an of_node_get on each iteration, so
a break out of the loop requires an of_node_put.

The of_node_put is duplicated in front of each error return, because the
function contains a later error return that is beyond the end of the
for_each_child_of_node and thus doesn't need of_node_put.

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

// <smpl>
@@
expression root,e;
local idexpression child;
iterator name for_each_child_of_node;
@@

 for_each_child_of_node(root, child) {
   ... when != of_node_put(child)
       when != e = child
(
   return child;
|
+  of_node_put(child);
?  return ...;
)
   ...
 }

@@
expression root,e;
local idexpression child;
@@

 for_each_child_of_node(root, child) {
   ... when != of_node_put(child)
       when != e = child
+  of_node_put(child);
?  break;
   ...
}
... when != child
// </smpl>

Additionally, concatenated a string in an affected line to avoid introducing
a checkpatch warning.

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

---

v2: Fixed the returns as well, adjusted a string in a test expression.

 arch/arm/kernel/devtree.c |   12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/arch/arm/kernel/devtree.c b/arch/arm/kernel/devtree.c
index 11c54de..65addcb 100644
--- a/arch/arm/kernel/devtree.c
+++ b/arch/arm/kernel/devtree.c
@@ -101,6 +101,7 @@ void __init arm_dt_init_cpu_maps(void)
 		if (of_property_read_u32(cpu, "reg", &hwid)) {
 			pr_debug(" * %s missing reg property\n",
 				     cpu->full_name);
+			of_node_put(cpu);
 			return;
 		}
 
@@ -108,8 +109,10 @@ void __init arm_dt_init_cpu_maps(void)
 		 * 8 MSBs must be set to 0 in the DT since the reg property
 		 * defines the MPIDR[23:0].
 		 */
-		if (hwid & ~MPIDR_HWID_BITMASK)
+		if (hwid & ~MPIDR_HWID_BITMASK) {
+			of_node_put(cpu);
 			return;
+		}
 
 		/*
 		 * Duplicate MPIDRs are a recipe for disaster.
@@ -119,9 +122,11 @@ void __init arm_dt_init_cpu_maps(void)
 		 * to avoid matching valid MPIDR[23:0] values.
 		 */
 		for (j = 0; j < cpuidx; j++)
-			if (WARN(tmp_map[j] = hwid, "Duplicate /cpu reg "
-						     "properties in the DT\n"))
+			if (WARN(tmp_map[j] = hwid,
+				 "Duplicate /cpu reg properties in the DT\n")) {
+				of_node_put(cpu);
 				return;
+			}
 
 		/*
 		 * Build a stashed array of MPIDR values. Numbering scheme
@@ -143,6 +148,7 @@ void __init arm_dt_init_cpu_maps(void)
 					       "max cores %u, capping them\n",
 					       cpuidx, nr_cpu_ids)) {
 			cpuidx = nr_cpu_ids;
+			of_node_put(cpu);
 			break;
 		}
 

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

* Re: [PATCH 3/5] ARM: shmobile: R-Mobile: add missing of_node_put
  2015-10-10 12:30 ` [PATCH 3/5] ARM: shmobile: R-Mobile: " Julia Lawall
@ 2015-10-12  0:16   ` Simon Horman
  2015-10-12  7:18   ` Geert Uytterhoeven
  1 sibling, 0 replies; 66+ messages in thread
From: Simon Horman @ 2015-10-12  0:16 UTC (permalink / raw)
  To: linux-arm-kernel

On Sat, Oct 10, 2015 at 02:30:52PM +0200, Julia Lawall wrote:
> for_each_child_of_node performs an of_node_get on each iteration, so
> a break out of the loop requires an of_node_put.
> 
> The semantic patch that fixes this problem is as follows
> (http://coccinelle.lip6.fr):
> 
> // <smpl>
> @@
> expression root,e;
> local idexpression child;
> @@
> 
>  for_each_child_of_node(root, child) {
>    ... when != of_node_put(child)
>        when != e = child
> (
>    return child;
> |
> +  of_node_put(child);
> ?  return ...;
> )
>    ...
>  }
> // </smpl>
> 
> Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>

Thanks, I have queued this up as a cleanup for v4.4.

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

* Re: [PATCH 4/5] regulator: of: add missing of_node_put
  2015-10-10 12:30 ` [PATCH 4/5] regulator: of: " Julia Lawall
@ 2015-10-12  0:33   ` Krzysztof Kozlowski
  2015-10-12  5:35     ` Julia Lawall
  2015-10-12 12:44     ` Julia Lawall
  2018-02-12 12:09   ` Applied "regulator: of: Add a missing 'of_node_put()' in an error handling path of 'of_regulator_mat Mark Brown
  1 sibling, 2 replies; 66+ messages in thread
From: Krzysztof Kozlowski @ 2015-10-12  0:33 UTC (permalink / raw)
  To: Julia Lawall
  Cc: Liam Girdwood, kernel-janitors, Mark Brown, linux-kernel,
	Russell King - ARM Linux, Thomas Petazzoni, Andrew Lunn,
	Bjorn Helgaas, Jason Cooper

2015-10-10 21:30 GMT+09:00 Julia Lawall <Julia.Lawall@lip6.fr>:
>
> for_each_child_of_node performs an of_node_get on each iteration, so
> a break out of the loop requires an of_node_put.
>
> The semantic patch that fixes this problem is as follows
> (http://coccinelle.lip6.fr):
>
> // <smpl>
> @@
> expression root,e;
> local idexpression child;
> @@
>
>  for_each_child_of_node(root, child) {
>    ... when != of_node_put(child)
>        when != e = child
> (
>    return child;
> |
> +  of_node_put(child);
> ?  return ...;
> )
>    ...
>  }
> // </smpl>
>
> Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
>
> ---
>  drivers/regulator/of_regulator.c |    1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/drivers/regulator/of_regulator.c b/drivers/regulator/of_regulator.c
> index 499e437..f9d77b4 100644
> --- a/drivers/regulator/of_regulator.c
> +++ b/drivers/regulator/of_regulator.c
> @@ -274,6 +274,7 @@ int of_regulator_match(struct device *dev, struct device_node *node,
>                                 dev_err(dev,
>                                         "failed to parse DT for regulator %s\n",
>                                         child->name);
> +                               of_node_put(child);

This looks good.

>                                 return -EINVAL;
>                         }
>                         match->of_node = of_node_get(child);

But what about 'break' few lines below? The reference from last
of_get_next_child() should be also dropped because... or we should
remove this of_node_get() call.

How about fixing also usage of for_each_available_child_of_node() in
regulator_of_get_init_data()?

Best regards,
Krzysztof

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

* Re: [PATCH 2/5] power_supply: charger-manager: add missing of_node_put
  2015-10-10 12:30 ` [PATCH 2/5] power_supply: charger-manager: " Julia Lawall
@ 2015-10-12  2:20   ` Krzysztof Kozlowski
  2015-10-15  8:56   ` Sebastian Reichel
  1 sibling, 0 replies; 66+ messages in thread
From: Krzysztof Kozlowski @ 2015-10-12  2:20 UTC (permalink / raw)
  To: Julia Lawall
  Cc: Sebastian Reichel, kernel-janitors, Dmitry Eremin-Solenikov,
	David Woodhouse, linux-pm, linux-kernel,
	Russell King - ARM Linux, Thomas Petazzoni, Andrew Lunn,
	Bjorn Helgaas, Jason Cooper

2015-10-10 21:30 GMT+09:00 Julia Lawall <Julia.Lawall@lip6.fr>:
> for_each_child_of_node performs an of_node_get on each iteration, so
> a break out of the loop requires an of_node_put.
>
> The semantic patch that fixes this problem is as follows
> (http://coccinelle.lip6.fr):
>
> // <smpl>
> @@
> expression root,e;
> local idexpression child;
> @@
>
>  for_each_child_of_node(root, child) {
>    ... when != of_node_put(child)
>        when != e = child
> (
>    return child;
> |
> +  of_node_put(child);
> ?  return ...;
> )
>    ...
>  }
> // </smpl>
>
> Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
>
> ---
>  drivers/power/charger-manager.c |    4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
>

Reviewed-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>

Best regards,
Krzysztof

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

* Re: [PATCH 4/5] regulator: of: add missing of_node_put
  2015-10-12  0:33   ` Krzysztof Kozlowski
@ 2015-10-12  5:35     ` Julia Lawall
  2015-10-12 12:44     ` Julia Lawall
  1 sibling, 0 replies; 66+ messages in thread
From: Julia Lawall @ 2015-10-12  5:35 UTC (permalink / raw)
  To: Krzysztof Kozlowski
  Cc: Liam Girdwood, kernel-janitors, Mark Brown, linux-kernel,
	Russell King - ARM Linux, Thomas Petazzoni, Andrew Lunn,
	Bjorn Helgaas, Jason Cooper



On Mon, 12 Oct 2015, Krzysztof Kozlowski wrote:

> 2015-10-10 21:30 GMT+09:00 Julia Lawall <Julia.Lawall@lip6.fr>:
> >
> > for_each_child_of_node performs an of_node_get on each iteration, so
> > a break out of the loop requires an of_node_put.
> >
> > The semantic patch that fixes this problem is as follows
> > (http://coccinelle.lip6.fr):
> >
> > // <smpl>
> > @@
> > expression root,e;
> > local idexpression child;
> > @@
> >
> >  for_each_child_of_node(root, child) {
> >    ... when != of_node_put(child)
> >        when != e = child
> > (
> >    return child;
> > |
> > +  of_node_put(child);
> > ?  return ...;
> > )
> >    ...
> >  }
> > // </smpl>
> >
> > Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
> >
> > ---
> >  drivers/regulator/of_regulator.c |    1 +
> >  1 file changed, 1 insertion(+)
> >
> > diff --git a/drivers/regulator/of_regulator.c b/drivers/regulator/of_regulator.c
> > index 499e437..f9d77b4 100644
> > --- a/drivers/regulator/of_regulator.c
> > +++ b/drivers/regulator/of_regulator.c
> > @@ -274,6 +274,7 @@ int of_regulator_match(struct device *dev, struct device_node *node,
> >                                 dev_err(dev,
> >                                         "failed to parse DT for regulator %s\n",
> >                                         child->name);
> > +                               of_node_put(child);
> 
> This looks good.
> 
> >                                 return -EINVAL;
> >                         }
> >                         match->of_node = of_node_get(child);
> 
> But what about 'break' few lines below? The reference from last
> of_get_next_child() should be also dropped because... or we should
> remove this of_node_get() call.
> 
> How about fixing also usage of for_each_available_child_of_node() in
> regulator_of_get_init_data()?

I'll check on all of this and resend.  Thanks for the feedback.

julia

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

* Re: [PATCH 3/5] ARM: shmobile: R-Mobile: add missing of_node_put
  2015-10-10 12:30 ` [PATCH 3/5] ARM: shmobile: R-Mobile: " Julia Lawall
  2015-10-12  0:16   ` Simon Horman
@ 2015-10-12  7:18   ` Geert Uytterhoeven
  2015-10-12  7:24     ` Julia Lawall
  2015-10-12  7:29     ` Thomas Petazzoni
  1 sibling, 2 replies; 66+ messages in thread
From: Geert Uytterhoeven @ 2015-10-12  7:18 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Julia,

On Sat, Oct 10, 2015 at 2:30 PM, Julia Lawall <Julia.Lawall@lip6.fr> wrote:
> --- a/arch/arm/mach-shmobile/pm-rmobile.c
> +++ b/arch/arm/mach-shmobile/pm-rmobile.c
> @@ -313,8 +313,10 @@ static int __init rmobile_add_pm_domains(void __iomem *base,
>                 }
>
>                 pd = kzalloc(sizeof(*pd), GFP_KERNEL);
> -               if (!pd)
> +               if (!pd) {
> +                       of_node_put(np);
>                         return -ENOMEM;
> +               }

While technically this patch is correct, the system will be dead anyway if it
ever goes OOM at core_initcall() time.

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

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

* Re: [PATCH 3/5] ARM: shmobile: R-Mobile: add missing of_node_put
  2015-10-12  7:18   ` Geert Uytterhoeven
@ 2015-10-12  7:24     ` Julia Lawall
  2015-10-12  7:26       ` Geert Uytterhoeven
  2015-10-12  7:29     ` Thomas Petazzoni
  1 sibling, 1 reply; 66+ messages in thread
From: Julia Lawall @ 2015-10-12  7:24 UTC (permalink / raw)
  To: linux-arm-kernel



On Mon, 12 Oct 2015, Geert Uytterhoeven wrote:

> Hi Julia,
>
> On Sat, Oct 10, 2015 at 2:30 PM, Julia Lawall <Julia.Lawall@lip6.fr> wrote:
> > --- a/arch/arm/mach-shmobile/pm-rmobile.c
> > +++ b/arch/arm/mach-shmobile/pm-rmobile.c
> > @@ -313,8 +313,10 @@ static int __init rmobile_add_pm_domains(void __iomem *base,
> >                 }
> >
> >                 pd = kzalloc(sizeof(*pd), GFP_KERNEL);
> > -               if (!pd)
> > +               if (!pd) {
> > +                       of_node_put(np);
> >                         return -ENOMEM;
> > +               }
>
> While technically this patch is correct, the system will be dead anyway if it
> ever goes OOM at core_initcall() time.

Maybe it would be better for the code to be correct to serve as an example
(or to avoid serving as a bad example) for others?

julia

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

* Re: [PATCH 3/5] ARM: shmobile: R-Mobile: add missing of_node_put
  2015-10-12  7:24     ` Julia Lawall
@ 2015-10-12  7:26       ` Geert Uytterhoeven
  0 siblings, 0 replies; 66+ messages in thread
From: Geert Uytterhoeven @ 2015-10-12  7:26 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Julia,

On Mon, Oct 12, 2015 at 9:24 AM, Julia Lawall <julia.lawall@lip6.fr> wrote:
> On Mon, 12 Oct 2015, Geert Uytterhoeven wrote:
>> On Sat, Oct 10, 2015 at 2:30 PM, Julia Lawall <Julia.Lawall@lip6.fr> wrote:
>> > --- a/arch/arm/mach-shmobile/pm-rmobile.c
>> > +++ b/arch/arm/mach-shmobile/pm-rmobile.c
>> > @@ -313,8 +313,10 @@ static int __init rmobile_add_pm_domains(void __iomem *base,
>> >                 }
>> >
>> >                 pd = kzalloc(sizeof(*pd), GFP_KERNEL);
>> > -               if (!pd)
>> > +               if (!pd) {
>> > +                       of_node_put(np);
>> >                         return -ENOMEM;
>> > +               }
>>
>> While technically this patch is correct, the system will be dead anyway if it
>> ever goes OOM at core_initcall() time.
>
> Maybe it would be better for the code to be correct to serve as an example
> (or to avoid serving as a bad example) for others?

Sure, as it's only a single call, that's fine for me.

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

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

* Re: [PATCH 3/5] ARM: shmobile: R-Mobile: add missing of_node_put
  2015-10-12  7:18   ` Geert Uytterhoeven
  2015-10-12  7:24     ` Julia Lawall
@ 2015-10-12  7:29     ` Thomas Petazzoni
  2015-10-12  7:30       ` Geert Uytterhoeven
  1 sibling, 1 reply; 66+ messages in thread
From: Thomas Petazzoni @ 2015-10-12  7:29 UTC (permalink / raw)
  To: linux-arm-kernel

Dear Geert Uytterhoeven,

On Mon, 12 Oct 2015 09:18:52 +0200, Geert Uytterhoeven wrote:

> >                 pd = kzalloc(sizeof(*pd), GFP_KERNEL);
> > -               if (!pd)
> > +               if (!pd) {
> > +                       of_node_put(np);
> >                         return -ENOMEM;
> > +               }
> 
> While technically this patch is correct, the system will be dead anyway if it
> ever goes OOM at core_initcall() time.

Then BUG_ON(!pd); ?

Thomas
-- 
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com

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

* Re: [PATCH 3/5] ARM: shmobile: R-Mobile: add missing of_node_put
  2015-10-12  7:29     ` Thomas Petazzoni
@ 2015-10-12  7:30       ` Geert Uytterhoeven
  0 siblings, 0 replies; 66+ messages in thread
From: Geert Uytterhoeven @ 2015-10-12  7:30 UTC (permalink / raw)
  To: linux-arm-kernel

On Mon, Oct 12, 2015 at 9:29 AM, Thomas Petazzoni
<thomas.petazzoni@free-electrons.com> wrote:
> On Mon, 12 Oct 2015 09:18:52 +0200, Geert Uytterhoeven wrote:
>
>> >                 pd = kzalloc(sizeof(*pd), GFP_KERNEL);
>> > -               if (!pd)
>> > +               if (!pd) {
>> > +                       of_node_put(np);
>> >                         return -ENOMEM;
>> > +               }
>>
>> While technically this patch is correct, the system will be dead anyway if it
>> ever goes OOM at core_initcall() time.
>
> Then BUG_ON(!pd); ?

kzalloc() will scream anyway.

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

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

* Re: [PATCH 4/5] regulator: of: add missing of_node_put
  2015-10-12  0:33   ` Krzysztof Kozlowski
  2015-10-12  5:35     ` Julia Lawall
@ 2015-10-12 12:44     ` Julia Lawall
  2015-10-12 12:58       ` Krzysztof Kozlowski
  1 sibling, 1 reply; 66+ messages in thread
From: Julia Lawall @ 2015-10-12 12:44 UTC (permalink / raw)
  To: Krzysztof Kozlowski
  Cc: Liam Girdwood, kernel-janitors, Mark Brown, linux-kernel,
	Russell King - ARM Linux, Thomas Petazzoni, Andrew Lunn,
	Bjorn Helgaas, Jason Cooper



On Mon, 12 Oct 2015, Krzysztof Kozlowski wrote:

> 2015-10-10 21:30 GMT+09:00 Julia Lawall <Julia.Lawall@lip6.fr>:
> >
> > for_each_child_of_node performs an of_node_get on each iteration, so
> > a break out of the loop requires an of_node_put.
> >
> > The semantic patch that fixes this problem is as follows
> > (http://coccinelle.lip6.fr):
> >
> > // <smpl>
> > @@
> > expression root,e;
> > local idexpression child;
> > @@
> >
> >  for_each_child_of_node(root, child) {
> >    ... when != of_node_put(child)
> >        when != e = child
> > (
> >    return child;
> > |
> > +  of_node_put(child);
> > ?  return ...;
> > )
> >    ...
> >  }
> > // </smpl>
> >
> > Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
> >
> > ---
> >  drivers/regulator/of_regulator.c |    1 +
> >  1 file changed, 1 insertion(+)
> >
> > diff --git a/drivers/regulator/of_regulator.c b/drivers/regulator/of_regulator.c
> > index 499e437..f9d77b4 100644
> > --- a/drivers/regulator/of_regulator.c
> > +++ b/drivers/regulator/of_regulator.c
> > @@ -274,6 +274,7 @@ int of_regulator_match(struct device *dev, struct device_node *node,
> >                                 dev_err(dev,
> >                                         "failed to parse DT for regulator %s\n",
> >                                         child->name);
> > +                               of_node_put(child);
>
> This looks good.
>
> >                                 return -EINVAL;
> >                         }
> >                         match->of_node = of_node_get(child);
>
> But what about 'break' few lines below? The reference from last
> of_get_next_child() should be also dropped because... or we should
> remove this of_node_get() call.

Actually, the break is OK.  It's on the inner for loop, not the
for_each_child_of_node loop.  The for_each_child_of_node will still
decrement the reference count in the normal way.

julia

> How about fixing also usage of for_each_available_child_of_node() in
> regulator_of_get_init_data()?
>
> Best regards,
> Krzysztof
> --
> 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] 66+ messages in thread

* Re: [PATCH 4/5] regulator: of: add missing of_node_put
  2015-10-12 12:44     ` Julia Lawall
@ 2015-10-12 12:58       ` Krzysztof Kozlowski
  0 siblings, 0 replies; 66+ messages in thread
From: Krzysztof Kozlowski @ 2015-10-12 12:58 UTC (permalink / raw)
  To: Julia Lawall
  Cc: k.kozlowski.k, Liam Girdwood, kernel-janitors, Mark Brown,
	linux-kernel, Russell King - ARM Linux, Thomas Petazzoni,
	Andrew Lunn, Bjorn Helgaas, Jason Cooper

W dniu 12.10.2015 o 21:44, Julia Lawall pisze:
> 
> 
> On Mon, 12 Oct 2015, Krzysztof Kozlowski wrote:
> 
>> 2015-10-10 21:30 GMT+09:00 Julia Lawall <Julia.Lawall@lip6.fr>:
>>>
>>> for_each_child_of_node performs an of_node_get on each iteration, so
>>> a break out of the loop requires an of_node_put.
>>>
>>> The semantic patch that fixes this problem is as follows
>>> (http://coccinelle.lip6.fr):
>>>
>>> // <smpl>
>>> @@
>>> expression root,e;
>>> local idexpression child;
>>> @@
>>>
>>>  for_each_child_of_node(root, child) {
>>>    ... when != of_node_put(child)
>>>        when != e = child
>>> (
>>>    return child;
>>> |
>>> +  of_node_put(child);
>>> ?  return ...;
>>> )
>>>    ...
>>>  }
>>> // </smpl>
>>>
>>> Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
>>>
>>> ---
>>>  drivers/regulator/of_regulator.c |    1 +
>>>  1 file changed, 1 insertion(+)
>>>
>>> diff --git a/drivers/regulator/of_regulator.c b/drivers/regulator/of_regulator.c
>>> index 499e437..f9d77b4 100644
>>> --- a/drivers/regulator/of_regulator.c
>>> +++ b/drivers/regulator/of_regulator.c
>>> @@ -274,6 +274,7 @@ int of_regulator_match(struct device *dev, struct device_node *node,
>>>                                 dev_err(dev,
>>>                                         "failed to parse DT for regulator %s\n",
>>>                                         child->name);
>>> +                               of_node_put(child);
>>
>> This looks good.
>>
>>>                                 return -EINVAL;
>>>                         }
>>>                         match->of_node = of_node_get(child);
>>
>> But what about 'break' few lines below? The reference from last
>> of_get_next_child() should be also dropped because... or we should
>> remove this of_node_get() call.
> 
> Actually, the break is OK.  It's on the inner for loop, not the
> for_each_child_of_node loop.  The for_each_child_of_node will still
> decrement the reference count in the normal way.
> 
> julia

Yes, you're right. The patch looks good:
Reviewed-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>

Best regards,
Krzysztof

>> How about fixing also usage of for_each_available_child_of_node() in
>> regulator_of_get_init_data()?
>>
>> Best regards,
>> Krzysztof
>> --
>> 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
>>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/
> 


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

* Re: [PATCH 1/5] backlight: 88pm860x_bl: add missing of_node_put
  2015-10-10 12:30 ` [PATCH 1/5] backlight: 88pm860x_bl: " Julia Lawall
@ 2015-10-13  8:15   ` Lee Jones
  0 siblings, 0 replies; 66+ messages in thread
From: Lee Jones @ 2015-10-13  8:15 UTC (permalink / raw)
  To: Julia Lawall
  Cc: Jingoo Han, kernel-janitors, Jean-Christophe Plagniol-Villard,
	Tomi Valkeinen, linux-fbdev, linux-kernel,
	Russell King - ARM Linux, Thomas Petazzoni, Andrew Lunn,
	Bjorn Helgaas, Jason Cooper

On Sat, 10 Oct 2015, Julia Lawall wrote:

> for_each_child_of_node performs an of_node_get on each iteration, so
> a break out of the loop requires an of_node_put.
> 
> The semantic patch that fixes this problem is as follows
> (http://coccinelle.lip6.fr):
> 
> // <smpl>
> @@
> expression root,e;
> local idexpression child;
> iterator name for_each_child_of_node;
> @@
> 
>  for_each_child_of_node(root, child) {
>    ... when != of_node_put(child)
>        when != e = child
> +  of_node_put(child);
> ?  break;
>    ...
> }
> ... when != child
> // </smpl>
> 
> Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
> 
> ---
>  drivers/video/backlight/88pm860x_bl.c |    1 +
>  1 file changed, 1 insertion(+)

Applied, thanks.

> diff --git a/drivers/video/backlight/88pm860x_bl.c b/drivers/video/backlight/88pm860x_bl.c
> index 2da5862..6d8dc2c 100644
> --- a/drivers/video/backlight/88pm860x_bl.c
> +++ b/drivers/video/backlight/88pm860x_bl.c
> @@ -180,6 +180,7 @@ static int pm860x_backlight_dt_init(struct platform_device *pdev,
>  			data->iset = PM8606_WLED_CURRENT(iset);
>  			of_property_read_u32(np, "marvell,88pm860x-pwm",
>  					     &data->pwm);
> +			of_node_put(np);
>  			break;
>  		}
>  	}
> 

-- 
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
--
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] 66+ messages in thread

* Re: [PATCH 2/5] power_supply: charger-manager: add missing of_node_put
  2015-10-10 12:30 ` [PATCH 2/5] power_supply: charger-manager: " Julia Lawall
  2015-10-12  2:20   ` Krzysztof Kozlowski
@ 2015-10-15  8:56   ` Sebastian Reichel
  1 sibling, 0 replies; 66+ messages in thread
From: Sebastian Reichel @ 2015-10-15  8:56 UTC (permalink / raw)
  To: Julia Lawall
  Cc: kernel-janitors, Dmitry Eremin-Solenikov, David Woodhouse,
	linux-pm, linux-kernel, Russell King - ARM Linux,
	Thomas Petazzoni, Andrew Lunn, Bjorn Helgaas, Jason Cooper

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

Hi,

On Sat, Oct 10, 2015 at 02:30:51PM +0200, Julia Lawall wrote:
> for_each_child_of_node performs an of_node_get on each iteration, so
> a break out of the loop requires an of_node_put.
> 
> The semantic patch that fixes this problem is as follows
> (http://coccinelle.lip6.fr):
> 
> // <smpl>
> @@
> expression root,e;
> local idexpression child;
> @@
> 
>  for_each_child_of_node(root, child) {
>    ... when != of_node_put(child)
>        when != e = child
> (
>    return child;
> |
> +  of_node_put(child);
> ?  return ...;
> )
>    ...
>  }
> // </smpl>

Thanks, queued.

-- Sebastian

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

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

* [PATCH 0/5] add missing of_node_put
  2015-10-10 12:30 [PATCH 0/5] add missing of_node_put Julia Lawall
                   ` (4 preceding siblings ...)
  2015-10-10 12:30 ` [PATCH 5/5] arm: add missing of_node_put Julia Lawall
@ 2015-10-21 20:41 ` Julia Lawall
  2015-10-21 20:41   ` [PATCH 1/5] clk: " Julia Lawall
                     ` (4 more replies)
  2015-12-21 16:39 ` [PATCH 0/5] " Julia Lawall
  2018-05-23 19:07 ` [PATCH 0/5] " Julia Lawall
  7 siblings, 5 replies; 66+ messages in thread
From: Julia Lawall @ 2015-10-21 20:41 UTC (permalink / raw)
  To: linux-arm-kernel

The various for_each device_node iterators performs an of_node_get on each
iteration, so a break out of the loop requires an of_node_put.

The complete semantic patch that fixes this problem is
(http://coccinelle.lip6.fr):

// <smpl>
@r@
local idexpression n;
expression e1,e2;
iterator name for_each_node_by_name, for_each_node_by_type,
for_each_compatible_node, for_each_matching_node,
for_each_matching_node_and_match, for_each_child_of_node,
for_each_available_child_of_node, for_each_node_with_property;
iterator i;
statement S;
expression list [n1] es;
@@

(
(
for_each_node_by_name(n,e1) S
|
for_each_node_by_type(n,e1) S
|
for_each_compatible_node(n,e1,e2) S
|
for_each_matching_node(n,e1) S
|
for_each_matching_node_and_match(n,e1,e2) S
|
for_each_child_of_node(e1,n) S
|
for_each_available_child_of_node(e1,n) S
|
for_each_node_with_property(n,e1) S
)
&
i(es,n,...) S
)

@@
local idexpression r.n;
iterator r.i;
expression e;
expression list [r.n1] es;
@@

 i(es,n,...) {
   ...
(
   of_node_put(n);
|
   e = n
|
   return n;
|
+  of_node_put(n);
?  return ...;
)
   ...
 }

@@
local idexpression r.n;
iterator r.i;
expression e;
expression list [r.n1] es;
@@

 i(es,n,...) {
   ...
(
   of_node_put(n);
|
   e = n
|
+  of_node_put(n);
?  break;
)
   ...
 }
... when != n

@@
local idexpression r.n;
iterator r.i;
expression e;
identifier l;
expression list [r.n1] es;
@@

 i(es,n,...) {
   ...
(
   of_node_put(n);
|
   e = n
|
+  of_node_put(n);
?  goto l;
)
   ...
 }
...
l: ... when != n// </smpl>

---

 drivers/clk/clk-scpi.c      |    1 +
 drivers/clk/clk-si5351.c    |   17 ++++++++++-------
 drivers/clk/clk.c           |    4 ++++
 drivers/clk/imx/clk-imx27.c |    4 +++-
 drivers/clk/imx/clk-imx31.c |    4 +++-
 5 files changed, 21 insertions(+), 9 deletions(-)

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

* [PATCH 1/5] clk: add missing of_node_put
  2015-10-21 20:41 ` [PATCH 0/5] " Julia Lawall
@ 2015-10-21 20:41   ` Julia Lawall
  2015-10-21 23:13     ` Stephen Boyd
  2015-10-21 20:41   ` [PATCH 2/5] clk: si5351: " Julia Lawall
                     ` (3 subsequent siblings)
  4 siblings, 1 reply; 66+ messages in thread
From: Julia Lawall @ 2015-10-21 20:41 UTC (permalink / raw)
  To: Michael Turquette
  Cc: kernel-janitors, Stephen Boyd, linux-clk, linux-kernel,
	Russell King - ARM Linux, Thomas Petazzoni, Andrew Lunn,
	Bjorn Helgaas, Jason Cooper

for_each_matching_node_and_match performs an of_node_get on each iteration,
so a break out of the loop requires an of_node_put.

A simplified version of the semantic patch that fixes this problem is as
follows (http://coccinelle.lip6.fr):

// <smpl>
@@
expression e1,e2,e;
local idexpression np;
@@

 for_each_matching_node_and_match(np, e1, e2) {
   ... when != of_node_put(np)
       when != e = np
(
   return np;
|
+  of_node_put(np);
?  return ...;
)
   ...
 }
// </smpl>

Besides the problem identified by the semantic patch, this patch adds an
of_node_get in front of saving np in a field of parent, to account for the
fact that this value will be put on going on to the next element in the
iteration, and then adds of_node_puts in the two loops where the parent
pointer can be freed.

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

---
 drivers/clk/clk.c |    4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index e735eab..11babd1 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -3200,12 +3200,15 @@ void __init of_clk_init(const struct of_device_id *matches)
 			list_for_each_entry_safe(clk_provider, next,
 						 &clk_provider_list, node) {
 				list_del(&clk_provider->node);
+				of_node_put(clk_provider->np);
 				kfree(clk_provider);
 			}
+			of_node_put(np);
 			return;
 		}
 
 		parent->clk_init_cb = match->data;
+		of_node_get(np);
 		parent->np = np;
 		list_add_tail(&parent->node, &clk_provider_list);
 	}
@@ -3220,6 +3223,7 @@ void __init of_clk_init(const struct of_device_id *matches)
 				of_clk_set_defaults(clk_provider->np, true);
 
 				list_del(&clk_provider->node);
+				of_node_put(clk_provider->np);
 				kfree(clk_provider);
 				is_init_done = true;
 			}


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

* [PATCH 2/5] clk: si5351: add missing of_node_put
  2015-10-21 20:41 ` [PATCH 0/5] " Julia Lawall
  2015-10-21 20:41   ` [PATCH 1/5] clk: " Julia Lawall
@ 2015-10-21 20:41   ` Julia Lawall
  2015-10-21 23:14     ` Stephen Boyd
  2015-10-21 20:41   ` [PATCH 3/5] clk: imx27: " Julia Lawall
                     ` (2 subsequent siblings)
  4 siblings, 1 reply; 66+ messages in thread
From: Julia Lawall @ 2015-10-21 20:41 UTC (permalink / raw)
  To: Michael Turquette
  Cc: kernel-janitors, Stephen Boyd, linux-clk, linux-kernel,
	Russell King - ARM Linux, Thomas Petazzoni, Andrew Lunn,
	Bjorn Helgaas, Jason Cooper

for_each_child_of_node performs an of_node_get on each iteration, so
a break out of the loop requires an of_node_put.

A simplified version of the semantic patch that fixes this problem is as
follows (http://coccinelle.lip6.fr):

// <smpl>
@@
expression root,e;
local idexpression child;
@@

 for_each_child_of_node(root, child) {
   ... when != of_node_put(child)
       when != e = child
(
   return child;
|
+  of_node_put(child);
?  return ...;
)
   ...
 }
// </smpl>

The resulting puts were manually moved to the end of the function for
conciseness.

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

---
 drivers/clk/clk-si5351.c |   17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/drivers/clk/clk-si5351.c b/drivers/clk/clk-si5351.c
index 5596c0a..e346b22 100644
--- a/drivers/clk/clk-si5351.c
+++ b/drivers/clk/clk-si5351.c
@@ -1183,13 +1183,13 @@ static int si5351_dt_parse(struct i2c_client *client,
 		if (of_property_read_u32(child, "reg", &num)) {
 			dev_err(&client->dev, "missing reg property of %s\n",
 				child->name);
-			return -EINVAL;
+			goto put_child;
 		}
 
 		if (num >= 8 ||
 		    (variant = SI5351_VARIANT_A3 && num >= 3)) {
 			dev_err(&client->dev, "invalid clkout %d\n", num);
-			return -EINVAL;
+			goto put_child;
 		}
 
 		if (!of_property_read_u32(child, "silabs,multisynth-source",
@@ -1207,7 +1207,7 @@ static int si5351_dt_parse(struct i2c_client *client,
 				dev_err(&client->dev,
 					"invalid parent %d for multisynth %d\n",
 					val, num);
-				return -EINVAL;
+				goto put_child;
 			}
 		}
 
@@ -1230,7 +1230,7 @@ static int si5351_dt_parse(struct i2c_client *client,
 					dev_err(&client->dev,
 						"invalid parent %d for clkout %d\n",
 						val, num);
-					return -EINVAL;
+					goto put_child;
 				}
 				pdata->clkout[num].clkout_src  					SI5351_CLKOUT_SRC_CLKIN;
@@ -1239,7 +1239,7 @@ static int si5351_dt_parse(struct i2c_client *client,
 				dev_err(&client->dev,
 					"invalid parent %d for clkout %d\n",
 					val, num);
-				return -EINVAL;
+				goto put_child;
 			}
 		}
 
@@ -1256,7 +1256,7 @@ static int si5351_dt_parse(struct i2c_client *client,
 				dev_err(&client->dev,
 					"invalid drive strength %d for clkout %d\n",
 					val, num);
-				return -EINVAL;
+				goto put_child;
 			}
 		}
 
@@ -1283,7 +1283,7 @@ static int si5351_dt_parse(struct i2c_client *client,
 				dev_err(&client->dev,
 					"invalid disable state %d for clkout %d\n",
 					val, num);
-				return -EINVAL;
+				goto put_child;
 			}
 		}
 
@@ -1296,6 +1296,9 @@ static int si5351_dt_parse(struct i2c_client *client,
 	client->dev.platform_data = pdata;
 
 	return 0;
+put_child:
+	of_node_put(child);
+	return -EINVAL;
 }
 #else
 static int si5351_dt_parse(struct i2c_client *client, enum si5351_variant variant)


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

* [PATCH 3/5] clk: imx27: add missing of_node_put
  2015-10-21 20:41 ` [PATCH 0/5] " Julia Lawall
  2015-10-21 20:41   ` [PATCH 1/5] clk: " Julia Lawall
  2015-10-21 20:41   ` [PATCH 2/5] clk: si5351: " Julia Lawall
@ 2015-10-21 20:41   ` Julia Lawall
  2015-10-21 23:15     ` Stephen Boyd
  2015-10-21 20:41   ` [PATCH 4/5] clk: imx31: " Julia Lawall
  2015-10-21 20:41   ` [PATCH 5/5] clk: scpi: " Julia Lawall
  4 siblings, 1 reply; 66+ messages in thread
From: Julia Lawall @ 2015-10-21 20:41 UTC (permalink / raw)
  To: linux-arm-kernel

for_each_compatible_node performs an of_node_get on each iteration, so a
break out of the loop requires an of_node_put.

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

// <smpl>
@@
local idexpression n;
expression e;
@@

 for_each_compatible_node(n,...) {
   ...
(
   of_node_put(n);
|
   e = n
|
+  of_node_put(n);
?  break;
)
   ...
 }
... when != n
// </smpl>

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

---
 drivers/clk/imx/clk-imx27.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/clk/imx/clk-imx27.c b/drivers/clk/imx/clk-imx27.c
index 0d7b8df..cf5cf75 100644
--- a/drivers/clk/imx/clk-imx27.c
+++ b/drivers/clk/imx/clk-imx27.c
@@ -261,8 +261,10 @@ static void __init mx27_clocks_init_dt(struct device_node *np)
 		if (!of_device_is_compatible(refnp, "fsl,imx-osc26m"))
 			continue;
 
-		if (!of_property_read_u32(refnp, "clock-frequency", &fref))
+		if (!of_property_read_u32(refnp, "clock-frequency", &fref)) {
+			of_node_put(refnp);
 			break;
+		}
 	}
 
 	ccm = of_iomap(np, 0);


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

* [PATCH 4/5] clk: imx31: add missing of_node_put
  2015-10-21 20:41 ` [PATCH 0/5] " Julia Lawall
                     ` (2 preceding siblings ...)
  2015-10-21 20:41   ` [PATCH 3/5] clk: imx27: " Julia Lawall
@ 2015-10-21 20:41   ` Julia Lawall
  2015-10-21 23:15     ` Stephen Boyd
  2015-10-21 20:41   ` [PATCH 5/5] clk: scpi: " Julia Lawall
  4 siblings, 1 reply; 66+ messages in thread
From: Julia Lawall @ 2015-10-21 20:41 UTC (permalink / raw)
  To: linux-arm-kernel

for_each_compatible_node performs an of_node_get on each iteration, so a
break out of the loop requires an of_node_put.

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

// <smpl>
@@
local idexpression n;
expression e;
@@

 for_each_compatible_node(n,...) {
   ...
(
   of_node_put(n);
|
   e = n
|
+  of_node_put(n);
?  break;
)
   ...
 }
... when != n
// </smpl>

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

---
 drivers/clk/imx/clk-imx31.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/clk/imx/clk-imx31.c b/drivers/clk/imx/clk-imx31.c
index f65b8b1..6a96414 100644
--- a/drivers/clk/imx/clk-imx31.c
+++ b/drivers/clk/imx/clk-imx31.c
@@ -233,8 +233,10 @@ int __init mx31_clocks_init_dt(void)
 		if (!of_device_is_compatible(np, "fsl,imx-osc26m"))
 			continue;
 
-		if (!of_property_read_u32(np, "clock-frequency", &fref))
+		if (!of_property_read_u32(np, "clock-frequency", &fref)) {
+			of_node_put(np);
 			break;
+		}
 	}
 
 	_mx31_clocks_init(fref);


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

* [PATCH 5/5] clk: scpi: add missing of_node_put
  2015-10-21 20:41 ` [PATCH 0/5] " Julia Lawall
                     ` (3 preceding siblings ...)
  2015-10-21 20:41   ` [PATCH 4/5] clk: imx31: " Julia Lawall
@ 2015-10-21 20:41   ` Julia Lawall
  2015-10-21 23:17     ` Stephen Boyd
                       ` (2 more replies)
  4 siblings, 3 replies; 66+ messages in thread
From: Julia Lawall @ 2015-10-21 20:41 UTC (permalink / raw)
  To: linux-arm-kernel

for_each_available_child_of_node performs an of_node_get on each iteration,
so a break out of the loop requires an of_node_put.

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

// <smpl>
@@
expression root,e;
local idexpression child;
@@

 for_each_available_child_of_node(root, child) {
   ... when != of_node_put(child)
       when != e = child
(
   return child;
|
+  of_node_put(child);
?  return ...;
)
   ...
 }
// </smpl>

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

---
 drivers/clk/clk-scpi.c |    1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/clk/clk-scpi.c b/drivers/clk/clk-scpi.c
index 0b501a9..cd0f272 100644
--- a/drivers/clk/clk-scpi.c
+++ b/drivers/clk/clk-scpi.c
@@ -292,6 +292,7 @@ static int scpi_clocks_probe(struct platform_device *pdev)
 		ret = scpi_clk_add(dev, child, match);
 		if (ret) {
 			scpi_clocks_remove(pdev);
+			of_node_put(child);
 			return ret;
 		}
 	}


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

* Re: [PATCH 1/5] clk: add missing of_node_put
  2015-10-21 20:41   ` [PATCH 1/5] clk: " Julia Lawall
@ 2015-10-21 23:13     ` Stephen Boyd
  2015-10-22  5:52       ` Julia Lawall
  0 siblings, 1 reply; 66+ messages in thread
From: Stephen Boyd @ 2015-10-21 23:13 UTC (permalink / raw)
  To: Julia Lawall
  Cc: Michael Turquette, kernel-janitors, linux-clk, linux-kernel,
	Russell King - ARM Linux, Thomas Petazzoni, Andrew Lunn,
	Bjorn Helgaas, Jason Cooper

On 10/21, Julia Lawall wrote:
> for_each_matching_node_and_match performs an of_node_get on each iteration,
> so a break out of the loop requires an of_node_put.
> 
> A simplified version of the semantic patch that fixes this problem is as
> follows (http://coccinelle.lip6.fr):
> 
> // <smpl>
> @@
> expression e1,e2,e;
> local idexpression np;
> @@
> 
>  for_each_matching_node_and_match(np, e1, e2) {
>    ... when != of_node_put(np)
>        when != e = np
> (
>    return np;
> |
> +  of_node_put(np);
> ?  return ...;
> )
>    ...
>  }
> // </smpl>
> 
> Besides the problem identified by the semantic patch, this patch adds an
> of_node_get in front of saving np in a field of parent, to account for the
> fact that this value will be put on going on to the next element in the
> iteration, and then adds of_node_puts in the two loops where the parent
> pointer can be freed.
> 
> Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
> 
> ---

Applied to clk-next, except I collapsed the of_node_get() into
the assignment.

---8<---
diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index d366bfb66c58..2eae76f21d6f 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -3205,8 +3205,7 @@ void __init of_clk_init(const struct of_device_id *matches)
 		}
 
 		parent->clk_init_cb = match->data;
-		of_node_get(np);
-		parent->np = np;
+		parent->np = of_node_get(np);
 		list_add_tail(&parent->node, &clk_provider_list);
 	}
 

-- 
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project

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

* Re: [PATCH 2/5] clk: si5351: add missing of_node_put
  2015-10-21 20:41   ` [PATCH 2/5] clk: si5351: " Julia Lawall
@ 2015-10-21 23:14     ` Stephen Boyd
  0 siblings, 0 replies; 66+ messages in thread
From: Stephen Boyd @ 2015-10-21 23:14 UTC (permalink / raw)
  To: Julia Lawall
  Cc: Michael Turquette, kernel-janitors, linux-clk, linux-kernel,
	Russell King - ARM Linux, Thomas Petazzoni, Andrew Lunn,
	Bjorn Helgaas, Jason Cooper

On 10/21, Julia Lawall wrote:
> for_each_child_of_node performs an of_node_get on each iteration, so
> a break out of the loop requires an of_node_put.
> 
> A simplified version of the semantic patch that fixes this problem is as
> follows (http://coccinelle.lip6.fr):
> 
> // <smpl>
> @@
> expression root,e;
> local idexpression child;
> @@
> 
>  for_each_child_of_node(root, child) {
>    ... when != of_node_put(child)
>        when != e = child
> (
>    return child;
> |
> +  of_node_put(child);
> ?  return ...;
> )
>    ...
>  }
> // </smpl>
> 
> The resulting puts were manually moved to the end of the function for
> conciseness.
> 
> Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
> 
> ---

Applied to clk-next

-- 
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project

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

* Re: [PATCH 3/5] clk: imx27: add missing of_node_put
  2015-10-21 20:41   ` [PATCH 3/5] clk: imx27: " Julia Lawall
@ 2015-10-21 23:15     ` Stephen Boyd
  0 siblings, 0 replies; 66+ messages in thread
From: Stephen Boyd @ 2015-10-21 23:15 UTC (permalink / raw)
  To: linux-arm-kernel

On 10/21, Julia Lawall wrote:
> for_each_compatible_node performs an of_node_get on each iteration, so a
> break out of the loop requires an of_node_put.
> 
> The semantic patch that fixes this problem is as follows
> (http://coccinelle.lip6.fr):
> 
> // <smpl>
> @@
> local idexpression n;
> expression e;
> @@
> 
>  for_each_compatible_node(n,...) {
>    ...
> (
>    of_node_put(n);
> |
>    e = n
> |
> +  of_node_put(n);
> ?  break;
> )
>    ...
>  }
> ... when != n
> // </smpl>
> 
> Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
> 
> ---

Applied to clk-next

-- 
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project

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

* Re: [PATCH 4/5] clk: imx31: add missing of_node_put
  2015-10-21 20:41   ` [PATCH 4/5] clk: imx31: " Julia Lawall
@ 2015-10-21 23:15     ` Stephen Boyd
  0 siblings, 0 replies; 66+ messages in thread
From: Stephen Boyd @ 2015-10-21 23:15 UTC (permalink / raw)
  To: linux-arm-kernel

On 10/21, Julia Lawall wrote:
> for_each_compatible_node performs an of_node_get on each iteration, so a
> break out of the loop requires an of_node_put.
> 
> The semantic patch that fixes this problem is as follows
> (http://coccinelle.lip6.fr):
> 
> // <smpl>
> @@
> local idexpression n;
> expression e;
> @@
> 
>  for_each_compatible_node(n,...) {
>    ...
> (
>    of_node_put(n);
> |
>    e = n
> |
> +  of_node_put(n);
> ?  break;
> )
>    ...
>  }
> ... when != n
> // </smpl>
> 
> Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
> 
> ---

Applied to clk-next

-- 
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project

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

* Re: [PATCH 5/5] clk: scpi: add missing of_node_put
  2015-10-21 20:41   ` [PATCH 5/5] clk: scpi: " Julia Lawall
@ 2015-10-21 23:17     ` Stephen Boyd
  2015-10-22  9:21     ` Sudeep Holla
  2015-12-01  0:29     ` Stephen Boyd
  2 siblings, 0 replies; 66+ messages in thread
From: Stephen Boyd @ 2015-10-21 23:17 UTC (permalink / raw)
  To: linux-arm-kernel

On 10/21, Julia Lawall wrote:
> for_each_available_child_of_node performs an of_node_get on each iteration,
> so a break out of the loop requires an of_node_put.
> 
> The semantic patch that fixes this problem is as follows
> (http://coccinelle.lip6.fr):
> 
> // <smpl>
> @@
> expression root,e;
> local idexpression child;
> @@
> 
>  for_each_available_child_of_node(root, child) {
>    ... when != of_node_put(child)
>        when != e = child
> (
>    return child;
> |
> +  of_node_put(child);
> ?  return ...;
> )
>    ...
>  }
> // </smpl>
> 
> Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
> 
> ---

Acked-by: Stephen Boyd <sboyd@codeaurora.org>

-- 
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project

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

* Re: [PATCH 1/5] clk: add missing of_node_put
  2015-10-21 23:13     ` Stephen Boyd
@ 2015-10-22  5:52       ` Julia Lawall
  0 siblings, 0 replies; 66+ messages in thread
From: Julia Lawall @ 2015-10-22  5:52 UTC (permalink / raw)
  To: Stephen Boyd
  Cc: Michael Turquette, kernel-janitors, linux-clk, linux-kernel,
	Russell King - ARM Linux, Thomas Petazzoni, Andrew Lunn,
	Bjorn Helgaas, Jason Cooper



On Wed, 21 Oct 2015, Stephen Boyd wrote:

> On 10/21, Julia Lawall wrote:
> > for_each_matching_node_and_match performs an of_node_get on each iteration,
> > so a break out of the loop requires an of_node_put.
> > 
> > A simplified version of the semantic patch that fixes this problem is as
> > follows (http://coccinelle.lip6.fr):
> > 
> > // <smpl>
> > @@
> > expression e1,e2,e;
> > local idexpression np;
> > @@
> > 
> >  for_each_matching_node_and_match(np, e1, e2) {
> >    ... when != of_node_put(np)
> >        when != e = np
> > (
> >    return np;
> > |
> > +  of_node_put(np);
> > ?  return ...;
> > )
> >    ...
> >  }
> > // </smpl>
> > 
> > Besides the problem identified by the semantic patch, this patch adds an
> > of_node_get in front of saving np in a field of parent, to account for the
> > fact that this value will be put on going on to the next element in the
> > iteration, and then adds of_node_puts in the two loops where the parent
> > pointer can be freed.
> > 
> > Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
> > 
> > ---
> 
> Applied to clk-next, except I collapsed the of_node_get() into
> the assignment.
> 
> ---8<---
> diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
> index d366bfb66c58..2eae76f21d6f 100644
> --- a/drivers/clk/clk.c
> +++ b/drivers/clk/clk.c
> @@ -3205,8 +3205,7 @@ void __init of_clk_init(const struct of_device_id *matches)
>  		}
>  
>  		parent->clk_init_cb = match->data;
> -		of_node_get(np);
> -		parent->np = np;
> +		parent->np = of_node_get(np);

Thanks!

julia

>  		list_add_tail(&parent->node, &clk_provider_list);
>  	}
>  
> 
> -- 
> Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
> a Linux Foundation Collaborative Project
> --
> 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] 66+ messages in thread

* Re: [PATCH 5/5] clk: scpi: add missing of_node_put
  2015-10-21 20:41   ` [PATCH 5/5] clk: scpi: " Julia Lawall
  2015-10-21 23:17     ` Stephen Boyd
@ 2015-10-22  9:21     ` Sudeep Holla
  2015-11-26 17:29       ` Sudeep Holla
  2015-12-01  0:29     ` Stephen Boyd
  2 siblings, 1 reply; 66+ messages in thread
From: Sudeep Holla @ 2015-10-22  9:21 UTC (permalink / raw)
  To: linux-arm-kernel



On 21/10/15 21:41, Julia Lawall wrote:
> for_each_available_child_of_node performs an of_node_get on each iteration,
> so a break out of the loop requires an of_node_put.
>
> The semantic patch that fixes this problem is as follows
> (http://coccinelle.lip6.fr):
>
> // <smpl>
> @@
> expression root,e;
> local idexpression child;
> @@
>
>   for_each_available_child_of_node(root, child) {
>     ... when != of_node_put(child)
>         when != e = child
> (
>     return child;
> |
> +  of_node_put(child);
> ?  return ...;
> )
>     ...
>   }
> // </smpl>
>
> Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>

Thanks for the fix.

Acked-by: Sudeep Holla <sudeep.holla@arm.com>

PS: Since this driver is queued via arm-soc, it needs to go via them or
wait for v4.4-rc1 and then queue via clk tree.

-- 
Regards,
Sudeep

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

* Re: [PATCH 5/5] clk: scpi: add missing of_node_put
  2015-10-22  9:21     ` Sudeep Holla
@ 2015-11-26 17:29       ` Sudeep Holla
  2015-12-01  0:28         ` Stephen Boyd
  0 siblings, 1 reply; 66+ messages in thread
From: Sudeep Holla @ 2015-11-26 17:29 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Mike/Stephen,

On Thu, Oct 22, 2015 at 10:21 AM, Sudeep Holla <sudeep.holla@arm.com> wrote:
>
>
> Thanks for the fix.
>
> Acked-by: Sudeep Holla <sudeep.holla@arm.com>
>
> PS: Since this driver is queued via arm-soc, it needs to go via them or
> wait for v4.4-rc1 and then queue via clk tree.
>

Now that the driver is in mainline, can you take this fix via clk tree for
you next -rc fixes ?

Regards,
Sudeep

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

* Re: [PATCH 5/5] clk: scpi: add missing of_node_put
  2015-11-26 17:29       ` Sudeep Holla
@ 2015-12-01  0:28         ` Stephen Boyd
  0 siblings, 0 replies; 66+ messages in thread
From: Stephen Boyd @ 2015-12-01  0:28 UTC (permalink / raw)
  To: linux-arm-kernel

On 11/26, Sudeep Holla wrote:
> Hi Mike/Stephen,
> 
> On Thu, Oct 22, 2015 at 10:21 AM, Sudeep Holla <sudeep.holla@arm.com> wrote:
> >
> >
> > Thanks for the fix.
> >
> > Acked-by: Sudeep Holla <sudeep.holla@arm.com>
> >
> > PS: Since this driver is queued via arm-soc, it needs to go via them or
> > wait for v4.4-rc1 and then queue via clk tree.
> >
> 
> Now that the driver is in mainline, can you take this fix via clk tree for
> you next -rc fixes ?
> 

Sure.

-- 
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project

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

* Re: [PATCH 5/5] clk: scpi: add missing of_node_put
  2015-10-21 20:41   ` [PATCH 5/5] clk: scpi: " Julia Lawall
  2015-10-21 23:17     ` Stephen Boyd
  2015-10-22  9:21     ` Sudeep Holla
@ 2015-12-01  0:29     ` Stephen Boyd
  2 siblings, 0 replies; 66+ messages in thread
From: Stephen Boyd @ 2015-12-01  0:29 UTC (permalink / raw)
  To: linux-arm-kernel

On 10/21, Julia Lawall wrote:
> for_each_available_child_of_node performs an of_node_get on each iteration,
> so a break out of the loop requires an of_node_put.
> 
> The semantic patch that fixes this problem is as follows
> (http://coccinelle.lip6.fr):
> 
> // <smpl>
> @@
> expression root,e;
> local idexpression child;
> @@
> 
>  for_each_available_child_of_node(root, child) {
>    ... when != of_node_put(child)
>        when != e = child
> (
>    return child;
> |
> +  of_node_put(child);
> ?  return ...;
> )
>    ...
>  }
> // </smpl>
> 
> Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
> 
> ---

Applied to clk-fixes

-- 
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project

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

* [PATCH 0/5] add missing of_node_put
  2015-10-10 12:30 [PATCH 0/5] add missing of_node_put Julia Lawall
                   ` (5 preceding siblings ...)
  2015-10-21 20:41 ` [PATCH 0/5] " Julia Lawall
@ 2015-12-21 16:39 ` Julia Lawall
  2015-12-21 16:39   ` [PATCH 1/5] pinctrl-tegra: " Julia Lawall
                     ` (4 more replies)
  2018-05-23 19:07 ` [PATCH 0/5] " Julia Lawall
  7 siblings, 5 replies; 66+ messages in thread
From: Julia Lawall @ 2015-12-21 16:39 UTC (permalink / raw)
  To: linux-arm-kernel

The various for_each device_node iterators performs an of_node_get on each
iteration, so a break out of the loop requires an of_node_put.

The complete semantic patch that fixes this problem is
(http://coccinelle.lip6.fr):

// <smpl>
@r@
local idexpression n;
expression e1,e2;
iterator name for_each_node_by_name, for_each_node_by_type,
for_each_compatible_node, for_each_matching_node,
for_each_matching_node_and_match, for_each_child_of_node,
for_each_available_child_of_node, for_each_node_with_property;
iterator i;
statement S;
expression list [n1] es;
@@

(
(
for_each_node_by_name(n,e1) S
|
for_each_node_by_type(n,e1) S
|
for_each_compatible_node(n,e1,e2) S
|
for_each_matching_node(n,e1) S
|
for_each_matching_node_and_match(n,e1,e2) S
|
for_each_child_of_node(e1,n) S
|
for_each_available_child_of_node(e1,n) S
|
for_each_node_with_property(n,e1) S
)
&
i(es,n,...) S
)

@@
local idexpression r.n;
iterator r.i;
expression e;
expression list [r.n1] es;
@@

 i(es,n,...) {
   ...
(
   of_node_put(n);
|
   e = n
|
   return n;
|
+  of_node_put(n);
?  return ...;
)
   ...
 }

@@
local idexpression r.n;
iterator r.i;
expression e;
expression list [r.n1] es;
@@

 i(es,n,...) {
   ...
(
   of_node_put(n);
|
   e = n
|
+  of_node_put(n);
?  break;
)
   ...
 }
... when != n

@@
local idexpression r.n;
iterator r.i;
expression e;
identifier l;
expression list [r.n1] es;
@@

 i(es,n,...) {
   ...
(
   of_node_put(n);
|
   e = n
|
+  of_node_put(n);
?  goto l;
)
   ...
 }
...
l: ... when != n// </smpl>

---

 drivers/pinctrl/mediatek/pinctrl-mtk-common.c |    1 +
 drivers/pinctrl/pinctrl-rockchip.c            |    5 ++++-
 drivers/pinctrl/pinctrl-tegra-xusb.c          |    4 +++-
 drivers/pinctrl/pinctrl-tegra.c               |    1 +
 drivers/pinctrl/sh-pfc/pinctrl.c              |    4 +++-
 drivers/pinctrl/sirf/pinctrl-sirf.c           |    8 ++++++--
 6 files changed, 18 insertions(+), 5 deletions(-)

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

* [PATCH 1/5] pinctrl-tegra: add missing of_node_put
  2015-12-21 16:39 ` [PATCH 0/5] " Julia Lawall
@ 2015-12-21 16:39   ` Julia Lawall
  2015-12-22 12:44     ` Linus Walleij
  2015-12-21 16:39   ` [PATCH 2/5] pinctrl: sirf: " Julia Lawall
                     ` (3 subsequent siblings)
  4 siblings, 1 reply; 66+ messages in thread
From: Julia Lawall @ 2015-12-21 16:39 UTC (permalink / raw)
  To: Linus Walleij
  Cc: kernel-janitors, Stephen Warren, Thierry Reding,
	Alexandre Courbot, linux-gpio, linux-tegra, linux-kernel

for_each_child_of_node performs an of_node_get on each iteration, so a
return from the loop requires an of_node_put.

A simplified version of the semantic patch that fixes this problem is as
follows (http://coccinelle.lip6.fr):

// <smpl>
@@
local idexpression n;
expression e,e1;
@@

 for_each_child_of_node(e1,n) {
   ...
(
   of_node_put(n);
|
   e = n
|
   return n;
|
+  of_node_put(n);
?  return ...;
)
   ...
 }
// </smpl>

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

---
 drivers/pinctrl/pinctrl-tegra-xusb.c |    4 +++-
 drivers/pinctrl/pinctrl-tegra.c      |    1 +
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/pinctrl/pinctrl-tegra-xusb.c b/drivers/pinctrl/pinctrl-tegra-xusb.c
index 84a43e6..bd3aa5a 100644
--- a/drivers/pinctrl/pinctrl-tegra-xusb.c
+++ b/drivers/pinctrl/pinctrl-tegra-xusb.c
@@ -253,8 +253,10 @@ static int tegra_xusb_padctl_dt_node_to_map(struct pinctrl_dev *pinctrl,
 		err = tegra_xusb_padctl_parse_subnode(padctl, np, maps,
 						      &reserved_maps,
 						      num_maps);
-		if (err < 0)
+		if (err < 0) {
+			of_node_put(np);
 			return err;
+		}
 	}
 
 	return 0;
diff --git a/drivers/pinctrl/pinctrl-tegra.c b/drivers/pinctrl/pinctrl-tegra.c
index 0fd7fd2..9da4da2 100644
--- a/drivers/pinctrl/pinctrl-tegra.c
+++ b/drivers/pinctrl/pinctrl-tegra.c
@@ -217,6 +217,7 @@ static int tegra_pinctrl_dt_node_to_map(struct pinctrl_dev *pctldev,
 		if (ret < 0) {
 			pinctrl_utils_dt_free_map(pctldev, *map,
 				*num_maps);
+			of_node_put(np);
 			return ret;
 		}
 	}


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

* [PATCH 2/5] pinctrl: sirf: add missing of_node_put
  2015-12-21 16:39 ` [PATCH 0/5] " Julia Lawall
  2015-12-21 16:39   ` [PATCH 1/5] pinctrl-tegra: " Julia Lawall
@ 2015-12-21 16:39   ` Julia Lawall
  2015-12-22 12:45     ` Linus Walleij
  2015-12-21 16:39   ` [PATCH 3/5] pinctrl: sh-pfc: " Julia Lawall
                     ` (2 subsequent siblings)
  4 siblings, 1 reply; 66+ messages in thread
From: Julia Lawall @ 2015-12-21 16:39 UTC (permalink / raw)
  To: linux-arm-kernel

for_each_child_of_node performs an of_node_get on each iteration, so a
return from the loop requires an of_node_put.

A simplified version of the semantic patch that fixes this problem is as
follows (http://coccinelle.lip6.fr):

// <smpl>
@@
local idexpression n;
expression e,e1;
@@

 for_each_child_of_node(e1,n) {
   ...
(
   of_node_put(n);
|
   e = n
|
   return n;
|
+  of_node_put(n);
?  return ...;
)
   ...
 }
// </smpl>

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

---
 drivers/pinctrl/sirf/pinctrl-sirf.c |    8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/pinctrl/sirf/pinctrl-sirf.c b/drivers/pinctrl/sirf/pinctrl-sirf.c
index ae97bdc..18fe46d 100644
--- a/drivers/pinctrl/sirf/pinctrl-sirf.c
+++ b/drivers/pinctrl/sirf/pinctrl-sirf.c
@@ -85,12 +85,16 @@ static int sirfsoc_dt_node_to_map(struct pinctrl_dev *pctldev,
 	/* calculate number of maps required */
 	for_each_child_of_node(np_config, np) {
 		ret = of_property_read_string(np, "sirf,function", &function);
-		if (ret < 0)
+		if (ret < 0) {
+			of_node_put(np);
 			return ret;
+		}
 
 		ret = of_property_count_strings(np, "sirf,pins");
-		if (ret < 0)
+		if (ret < 0) {
+			of_node_put(np);
 			return ret;
+		}
 
 		count += ret;
 	}


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

* [PATCH 3/5] pinctrl: sh-pfc: add missing of_node_put
  2015-12-21 16:39 ` [PATCH 0/5] " Julia Lawall
  2015-12-21 16:39   ` [PATCH 1/5] pinctrl-tegra: " Julia Lawall
  2015-12-21 16:39   ` [PATCH 2/5] pinctrl: sirf: " Julia Lawall
@ 2015-12-21 16:39   ` Julia Lawall
  2015-12-21 20:46     ` Laurent Pinchart
  2015-12-22 12:47     ` Linus Walleij
  2015-12-21 16:39   ` [PATCH 4/5] pinctrl: rockchip: " Julia Lawall
  2015-12-21 16:39   ` [PATCH 5/5] pinctrl: mediatek: " Julia Lawall
  4 siblings, 2 replies; 66+ messages in thread
From: Julia Lawall @ 2015-12-21 16:39 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: kernel-janitors, Linus Walleij, linux-sh, linux-gpio, linux-kernel

for_each_child_of_node performs an of_node_get on each iteration, so a
goto out of the loop requires an of_node_put.

A simplified version of the semantic patch that fixes this problem is as
follows (http://coccinelle.lip6.fr):

// <smpl>
@@
local idexpression n;
expression e,e1;
identifier l;
@@

 for_each_child_of_node(e1,n) {
   ...
(
   of_node_put(n);
|
   e = n
|
   return n;
|
+  of_node_put(n);
?  goto l;
)
   ...
 }
l: ... when != n
// </smpl>

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

---
 drivers/pinctrl/sh-pfc/pinctrl.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/pinctrl/sh-pfc/pinctrl.c b/drivers/pinctrl/sh-pfc/pinctrl.c
index 863c3e3..87b0a59 100644
--- a/drivers/pinctrl/sh-pfc/pinctrl.c
+++ b/drivers/pinctrl/sh-pfc/pinctrl.c
@@ -273,8 +273,10 @@ static int sh_pfc_dt_node_to_map(struct pinctrl_dev *pctldev,
 	for_each_child_of_node(np, child) {
 		ret = sh_pfc_dt_subnode_to_map(pctldev, child, map, num_maps,
 					       &index);
-		if (ret < 0)
+		if (ret < 0) {
+			of_node_put(child);
 			goto done;
+		}
 	}
 
 	/* If no mapping has been found in child nodes try the config node. */


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

* [PATCH 4/5] pinctrl: rockchip: add missing of_node_put
  2015-12-21 16:39 ` [PATCH 0/5] " Julia Lawall
                     ` (2 preceding siblings ...)
  2015-12-21 16:39   ` [PATCH 3/5] pinctrl: sh-pfc: " Julia Lawall
@ 2015-12-21 16:39   ` Julia Lawall
  2015-12-21 21:20     ` Heiko Stübner
  2015-12-22 12:48     ` Linus Walleij
  2015-12-21 16:39   ` [PATCH 5/5] pinctrl: mediatek: " Julia Lawall
  4 siblings, 2 replies; 66+ messages in thread
From: Julia Lawall @ 2015-12-21 16:39 UTC (permalink / raw)
  To: linux-arm-kernel

for_each_child_of_node performs an of_node_get on each iteration, so a
return from the loop requires an of_node_put.

A simplified version of the semantic patch that fixes this problem is as
follows (http://coccinelle.lip6.fr):

// <smpl>
@@
local idexpression n;
expression e,e1;
@@

 for_each_child_of_node(e1,n) {
   ...
(
   of_node_put(n);
|
   e = n
|
   return n;
|
+  of_node_put(n);
?  return ...;
)
   ...
 }
// </smpl>

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

---
 drivers/pinctrl/pinctrl-rockchip.c |    5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/pinctrl/pinctrl-rockchip.c b/drivers/pinctrl/pinctrl-rockchip.c
index 2b88a40..d0305a2 100644
--- a/drivers/pinctrl/pinctrl-rockchip.c
+++ b/drivers/pinctrl/pinctrl-rockchip.c
@@ -1258,8 +1258,10 @@ static int rockchip_pinctrl_parse_functions(struct device_node *np,
 		func->groups[i] = child->name;
 		grp = &info->groups[grp_index++];
 		ret = rockchip_pinctrl_parse_groups(child, grp, info, i++);
-		if (ret)
+		if (ret) {
+			of_node_put(child);
 			return ret;
+		}
 	}
 
 	return 0;
@@ -1304,6 +1306,7 @@ static int rockchip_pinctrl_parse_dt(struct platform_device *pdev,
 		ret = rockchip_pinctrl_parse_functions(child, info, i++);
 		if (ret) {
 			dev_err(&pdev->dev, "failed to parse function\n");
+			of_node_put(child);
 			return ret;
 		}
 	}


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

* [PATCH 5/5] pinctrl: mediatek: add missing of_node_put
  2015-12-21 16:39 ` [PATCH 0/5] " Julia Lawall
                     ` (3 preceding siblings ...)
  2015-12-21 16:39   ` [PATCH 4/5] pinctrl: rockchip: " Julia Lawall
@ 2015-12-21 16:39   ` Julia Lawall
  2015-12-22 12:49     ` Linus Walleij
  4 siblings, 1 reply; 66+ messages in thread
From: Julia Lawall @ 2015-12-21 16:39 UTC (permalink / raw)
  To: linux-arm-kernel

for_each_child_of_node performs an of_node_get on each iteration, so a
return from the loop requires an of_node_put.

A simplified version of the semantic patch that fixes this problem is as
follows (http://coccinelle.lip6.fr):

// <smpl>
@@
local idexpression n;
expression e,e1;
@@

 for_each_child_of_node(e1,n) {
   ...
(
   of_node_put(n);
|
   e = n
|
   return n;
|
+  of_node_put(n);
?  return ...;
)
   ...
 }
// </smpl>

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

---
 drivers/pinctrl/mediatek/pinctrl-mtk-common.c |    1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/pinctrl/mediatek/pinctrl-mtk-common.c b/drivers/pinctrl/mediatek/pinctrl-mtk-common.c
index 45f3562..ee2287b 100644
--- a/drivers/pinctrl/mediatek/pinctrl-mtk-common.c
+++ b/drivers/pinctrl/mediatek/pinctrl-mtk-common.c
@@ -598,6 +598,7 @@ static int mtk_pctrl_dt_node_to_map(struct pinctrl_dev *pctldev,
 				&reserved_maps, num_maps);
 		if (ret < 0) {
 			pinctrl_utils_dt_free_map(pctldev, *map, *num_maps);
+			of_node_put(np);
 			return ret;
 		}
 	}


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

* Re: [PATCH 3/5] pinctrl: sh-pfc: add missing of_node_put
  2015-12-21 16:39   ` [PATCH 3/5] pinctrl: sh-pfc: " Julia Lawall
@ 2015-12-21 20:46     ` Laurent Pinchart
  2015-12-22 12:47     ` Linus Walleij
  1 sibling, 0 replies; 66+ messages in thread
From: Laurent Pinchart @ 2015-12-21 20:46 UTC (permalink / raw)
  To: Julia Lawall
  Cc: kernel-janitors, Linus Walleij, linux-sh, linux-gpio, linux-kernel

Hi Julia,

Thank you for the patch.

On Monday 21 December 2015 17:39:46 Julia Lawall wrote:
> for_each_child_of_node performs an of_node_get on each iteration, so a
> goto out of the loop requires an of_node_put.
> 
> A simplified version of the semantic patch that fixes this problem is as
> follows (http://coccinelle.lip6.fr):
> 
> // <smpl>
> @@
> local idexpression n;
> expression e,e1;
> identifier l;
> @@
> 
>  for_each_child_of_node(e1,n) {
>    ...
> (
>    of_node_put(n);
> 
>    e = n
> 
>    return n;
> 
> +  of_node_put(n);
> ?  goto l;
> )
>    ...
>  }
> l: ... when != n
> // </smpl>
> 
> Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> ---
>  drivers/pinctrl/sh-pfc/pinctrl.c |    4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/pinctrl/sh-pfc/pinctrl.c
> b/drivers/pinctrl/sh-pfc/pinctrl.c index 863c3e3..87b0a59 100644
> --- a/drivers/pinctrl/sh-pfc/pinctrl.c
> +++ b/drivers/pinctrl/sh-pfc/pinctrl.c
> @@ -273,8 +273,10 @@ static int sh_pfc_dt_node_to_map(struct pinctrl_dev
> *pctldev, for_each_child_of_node(np, child) {
>  		ret = sh_pfc_dt_subnode_to_map(pctldev, child, map, num_maps,
>  					       &index);
> -		if (ret < 0)
> +		if (ret < 0) {
> +			of_node_put(child);
>  			goto done;
> +		}
>  	}
> 
>  	/* If no mapping has been found in child nodes try the config node. */

-- 
Regards,

Laurent Pinchart


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

* Re: [PATCH 4/5] pinctrl: rockchip: add missing of_node_put
  2015-12-21 16:39   ` [PATCH 4/5] pinctrl: rockchip: " Julia Lawall
@ 2015-12-21 21:20     ` Heiko Stübner
  2015-12-22 12:48     ` Linus Walleij
  1 sibling, 0 replies; 66+ messages in thread
From: Heiko Stübner @ 2015-12-21 21:20 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Julia,

Am Montag, 21. Dezember 2015, 17:39:47 schrieb Julia Lawall:
> for_each_child_of_node performs an of_node_get on each iteration, so a
> return from the loop requires an of_node_put.
> 
> A simplified version of the semantic patch that fixes this problem is as
> follows (http://coccinelle.lip6.fr):
> 
> // <smpl>
> @@
> local idexpression n;
> expression e,e1;
> @@
> 
>  for_each_child_of_node(e1,n) {
>    ...
> (
>    of_node_put(n);
> 
>    e = n
> 
>    return n;
> 
> +  of_node_put(n);
> ?  return ...;
> )
>    ...
>  }
> // </smpl>
> 
> Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>

thanks for catching this :-)

I still remember how we talked about that same issue in the phy driver and the 
things for_each_child_of_node does when running, so

Reviewed-by: Heiko Stuebner <heiko@sntech.de>


Thanks
Heiko

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

* Re: [PATCH 1/5] pinctrl-tegra: add missing of_node_put
  2015-12-21 16:39   ` [PATCH 1/5] pinctrl-tegra: " Julia Lawall
@ 2015-12-22 12:44     ` Linus Walleij
  0 siblings, 0 replies; 66+ messages in thread
From: Linus Walleij @ 2015-12-22 12:44 UTC (permalink / raw)
  To: Julia Lawall
  Cc: kernel-janitors, Stephen Warren, Thierry Reding,
	Alexandre Courbot, linux-gpio, linux-tegra, linux-kernel

On Mon, Dec 21, 2015 at 5:39 PM, Julia Lawall <Julia.Lawall@lip6.fr> wrote:

> for_each_child_of_node performs an of_node_get on each iteration, so a
> return from the loop requires an of_node_put.
>
> A simplified version of the semantic patch that fixes this problem is as
> follows (http://coccinelle.lip6.fr):

Patch applied.

Yours,
Linus Walleij

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

* Re: [PATCH 2/5] pinctrl: sirf: add missing of_node_put
  2015-12-21 16:39   ` [PATCH 2/5] pinctrl: sirf: " Julia Lawall
@ 2015-12-22 12:45     ` Linus Walleij
  0 siblings, 0 replies; 66+ messages in thread
From: Linus Walleij @ 2015-12-22 12:45 UTC (permalink / raw)
  To: linux-arm-kernel

On Mon, Dec 21, 2015 at 5:39 PM, Julia Lawall <Julia.Lawall@lip6.fr> wrote:

> for_each_child_of_node performs an of_node_get on each iteration, so a
> return from the loop requires an of_node_put.
>
> A simplified version of the semantic patch that fixes this problem is as
> follows (http://coccinelle.lip6.fr):

Patch applied.

Yours,
Linus Walleij

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

* Re: [PATCH 3/5] pinctrl: sh-pfc: add missing of_node_put
  2015-12-21 16:39   ` [PATCH 3/5] pinctrl: sh-pfc: " Julia Lawall
  2015-12-21 20:46     ` Laurent Pinchart
@ 2015-12-22 12:47     ` Linus Walleij
  2015-12-22 13:23       ` Geert Uytterhoeven
  1 sibling, 1 reply; 66+ messages in thread
From: Linus Walleij @ 2015-12-22 12:47 UTC (permalink / raw)
  To: Julia Lawall, Geert Uytterhoeven
  Cc: Laurent Pinchart, kernel-janitors, linux-sh, linux-gpio, linux-kernel

On Mon, Dec 21, 2015 at 5:39 PM, Julia Lawall <Julia.Lawall@lip6.fr> wrote:

> for_each_child_of_node performs an of_node_get on each iteration, so a
> goto out of the loop requires an of_node_put.
>
> A simplified version of the semantic patch that fixes this problem is as
> follows (http://coccinelle.lip6.fr):

Patch applied with Laurent's ACK.

Geert: since I don't think you're gonna send me more pull
requests before the merge window I went ahead and applied
this directly, OK?

Yours,
Linus Walleij

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

* Re: [PATCH 4/5] pinctrl: rockchip: add missing of_node_put
  2015-12-21 16:39   ` [PATCH 4/5] pinctrl: rockchip: " Julia Lawall
  2015-12-21 21:20     ` Heiko Stübner
@ 2015-12-22 12:48     ` Linus Walleij
  1 sibling, 0 replies; 66+ messages in thread
From: Linus Walleij @ 2015-12-22 12:48 UTC (permalink / raw)
  To: linux-arm-kernel

On Mon, Dec 21, 2015 at 5:39 PM, Julia Lawall <Julia.Lawall@lip6.fr> wrote:

> for_each_child_of_node performs an of_node_get on each iteration, so a
> return from the loop requires an of_node_put.
>
> A simplified version of the semantic patch that fixes this problem is as
> follows (http://coccinelle.lip6.fr):

Patch applied with Heiko's review tag.

Yours,
Linus Walleij

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

* Re: [PATCH 5/5] pinctrl: mediatek: add missing of_node_put
  2015-12-21 16:39   ` [PATCH 5/5] pinctrl: mediatek: " Julia Lawall
@ 2015-12-22 12:49     ` Linus Walleij
  0 siblings, 0 replies; 66+ messages in thread
From: Linus Walleij @ 2015-12-22 12:49 UTC (permalink / raw)
  To: linux-arm-kernel

On Mon, Dec 21, 2015 at 5:39 PM, Julia Lawall <Julia.Lawall@lip6.fr> wrote:

> for_each_child_of_node performs an of_node_get on each iteration, so a
> return from the loop requires an of_node_put.
>
> A simplified version of the semantic patch that fixes this problem is as
> follows (http://coccinelle.lip6.fr):

Patch applied.

Yours,
Linus Walleij

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

* Re: [PATCH 3/5] pinctrl: sh-pfc: add missing of_node_put
  2015-12-22 12:47     ` Linus Walleij
@ 2015-12-22 13:23       ` Geert Uytterhoeven
  0 siblings, 0 replies; 66+ messages in thread
From: Geert Uytterhoeven @ 2015-12-22 13:23 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Julia Lawall, Geert Uytterhoeven, Laurent Pinchart,
	kernel-janitors, linux-sh, linux-gpio, linux-kernel

Hi Linus,

On Tue, Dec 22, 2015 at 1:47 PM, Linus Walleij <linus.walleij@linaro.org> wrote:
> On Mon, Dec 21, 2015 at 5:39 PM, Julia Lawall <Julia.Lawall@lip6.fr> wrote:
>> for_each_child_of_node performs an of_node_get on each iteration, so a
>> goto out of the loop requires an of_node_put.
>>
>> A simplified version of the semantic patch that fixes this problem is as
>> follows (http://coccinelle.lip6.fr):
>
> Patch applied with Laurent's ACK.
>
> Geert: since I don't think you're gonna send me more pull
> requests before the merge window I went ahead and applied
> this directly, OK?

You're reading my mind ;-)

Thanks!

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

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

* Applied "regulator: of: Add a missing 'of_node_put()' in an error handling path of 'of_regulator_mat
  2015-10-10 12:30 ` [PATCH 4/5] regulator: of: " Julia Lawall
  2015-10-12  0:33   ` Krzysztof Kozlowski
@ 2018-02-12 12:09   ` Mark Brown
  1 sibling, 0 replies; 66+ messages in thread
From: Mark Brown @ 2018-02-12 12:09 UTC (permalink / raw)
  To: Christophe JAILLET; +Cc: Mark Brown, Liam Girdwood, kernel-janitors

The patch

   regulator: of: Add a missing 'of_node_put()' in an error handling path of 'of_regulator_match()'

has been applied to the regulator tree at

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator.git 

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.  

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark

From 30966861a7a2051457be8c49466887d78cc47e97 Mon Sep 17 00:00:00 2001
From: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Date: Fri, 26 Jan 2018 23:13:44 +0100
Subject: [PATCH] regulator: of: Add a missing 'of_node_put()' in an error
 handling path of 'of_regulator_match()'

If an unlikely failure in 'of_get_regulator_init_data()' occurs, we must
release the reference on the current 'child' node before returning.

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Signed-off-by: Mark Brown <broonie@kernel.org>
---
 drivers/regulator/of_regulator.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/regulator/of_regulator.c b/drivers/regulator/of_regulator.c
index 092ed6efb3ec..f47264fa1940 100644
--- a/drivers/regulator/of_regulator.c
+++ b/drivers/regulator/of_regulator.c
@@ -321,6 +321,7 @@ int of_regulator_match(struct device *dev, struct device_node *node,
 				dev_err(dev,
 					"failed to parse DT for regulator %s\n",
 					child->name);
+				of_node_put(child);
 				return -EINVAL;
 			}
 			match->of_node = of_node_get(child);
-- 
2.16.1


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

* [PATCH 0/5] add missing of_node_put
  2015-10-10 12:30 [PATCH 0/5] add missing of_node_put Julia Lawall
                   ` (6 preceding siblings ...)
  2015-12-21 16:39 ` [PATCH 0/5] " Julia Lawall
@ 2018-05-23 19:07 ` Julia Lawall
  2018-05-23 19:07   ` [PATCH 1/5] pinctrl: at91-pio4: " Julia Lawall
                     ` (4 more replies)
  7 siblings, 5 replies; 66+ messages in thread
From: Julia Lawall @ 2018-05-23 19:07 UTC (permalink / raw)
  To: linux-pci
  Cc: linux-rockchip, kernel-janitors, linux-kernel, dri-devel,
	linux-gpio, linuxppc-dev, linux-arm-kernel

The device node iterators perform an of_node_get on each iteration, so a
jump out of the loop requires an of_node_put.

---

 drivers/gpu/drm/rockchip/rockchip_lvds.c   |    4 +++-
 drivers/pci/hotplug/pnv_php.c              |    8 ++++++--
 drivers/phy/hisilicon/phy-hisi-inno-usb2.c |    9 +++++++--
 drivers/pinctrl/pinctrl-at91-pio4.c        |    4 +++-
 drivers/soc/ti/knav_dma.c                  |    1 +
 5 files changed, 20 insertions(+), 6 deletions(-)

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

* [PATCH 1/5] pinctrl: at91-pio4: add missing of_node_put
  2018-05-23 19:07 ` [PATCH 0/5] " Julia Lawall
@ 2018-05-23 19:07   ` Julia Lawall
  2018-05-24  7:59     ` Ludovic Desroches
  2018-05-24  8:30     ` Linus Walleij
  2018-05-23 19:07   ` [PATCH 2/5] phy: " Julia Lawall
                     ` (3 subsequent siblings)
  4 siblings, 2 replies; 66+ messages in thread
From: Julia Lawall @ 2018-05-23 19:07 UTC (permalink / raw)
  To: linux-arm-kernel

The device node iterators perform an of_node_get on each iteration, so a
jump out of the loop requires an of_node_put.

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

// <smpl>
@@
expression root,e;
local idexpression child;
iterator name for_each_child_of_node;
@@

 for_each_child_of_node(root, child) {
   ... when != of_node_put(child)
       when != e = child
+  of_node_put(child);
?  break;
   ...
}
... when != child
// </smpl>

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

---
 drivers/pinctrl/pinctrl-at91-pio4.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/pinctrl/pinctrl-at91-pio4.c b/drivers/pinctrl/pinctrl-at91-pio4.c
index 4b57a13..bafb3d4 100644
--- a/drivers/pinctrl/pinctrl-at91-pio4.c
+++ b/drivers/pinctrl/pinctrl-at91-pio4.c
@@ -576,8 +576,10 @@ static int atmel_pctl_dt_node_to_map(struct pinctrl_dev *pctldev,
 		for_each_child_of_node(np_config, np) {
 			ret = atmel_pctl_dt_subnode_to_map(pctldev, np, map,
 						    &reserved_maps, num_maps);
-			if (ret < 0)
+			if (ret < 0) {
+				of_node_put(np);
 				break;
+			}
 		}
 	}
 


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

* [PATCH 2/5] phy: add missing of_node_put
  2018-05-23 19:07 ` [PATCH 0/5] " Julia Lawall
  2018-05-23 19:07   ` [PATCH 1/5] pinctrl: at91-pio4: " Julia Lawall
@ 2018-05-23 19:07   ` Julia Lawall
  2018-05-23 19:07   ` [PATCH 3/5] soc: ti: knav_dma: " Julia Lawall
                     ` (2 subsequent siblings)
  4 siblings, 0 replies; 66+ messages in thread
From: Julia Lawall @ 2018-05-23 19:07 UTC (permalink / raw)
  To: Kishon Vijay Abraham I; +Cc: kernel-janitors, linux-kernel

The device node iterators perform an of_node_get on each iteration, so a
jump out of the loop requires an of_node_put.

The semantic patch that fixes this problem in the break case is as follows
(http://coccinelle.lip6.fr):

// <smpl>
@@
expression root,e;
local idexpression child;
iterator name for_each_child_of_node;
@@

 for_each_child_of_node(root, child) {
   ... when != of_node_put(child)
       when != e = child
+  of_node_put(child);
?  break;
   ...
}
... when != child
// </smpl>

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

---
 drivers/phy/hisilicon/phy-hisi-inno-usb2.c |    9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/phy/hisilicon/phy-hisi-inno-usb2.c b/drivers/phy/hisilicon/phy-hisi-inno-usb2.c
index 5243812..0da14b6 100644
--- a/drivers/phy/hisilicon/phy-hisi-inno-usb2.c
+++ b/drivers/phy/hisilicon/phy-hisi-inno-usb2.c
@@ -154,14 +154,18 @@ static int hisi_inno_phy_probe(struct platform_device *pdev)
 		struct phy *phy;
 
 		rst = of_reset_control_get_exclusive(child, NULL);
-		if (IS_ERR(rst))
+		if (IS_ERR(rst)) {
+			of_node_put(child);
 			return PTR_ERR(rst);
+		}
 		priv->ports[i].utmi_rst = rst;
 		priv->ports[i].priv = priv;
 
 		phy = devm_phy_create(dev, child, &hisi_inno_phy_ops);
-		if (IS_ERR(phy))
+		if (IS_ERR(phy)) {
+			of_node_put(child);
 			return PTR_ERR(phy);
+		}
 
 		phy_set_bus_width(phy, 8);
 		phy_set_drvdata(phy, &priv->ports[i]);
@@ -169,6 +173,7 @@ static int hisi_inno_phy_probe(struct platform_device *pdev)
 
 		if (i > INNO_PHY_PORT_NUM) {
 			dev_warn(dev, "Support %d ports in maximum\n", i);
+			of_node_put(child);
 			break;
 		}
 	}


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

* [PATCH 3/5] soc: ti: knav_dma: add missing of_node_put
  2018-05-23 19:07 ` [PATCH 0/5] " Julia Lawall
  2018-05-23 19:07   ` [PATCH 1/5] pinctrl: at91-pio4: " Julia Lawall
  2018-05-23 19:07   ` [PATCH 2/5] phy: " Julia Lawall
@ 2018-05-23 19:07   ` Julia Lawall
  2018-05-23 19:07   ` [PATCH 4/5] pci/hotplug/pnv-php: " Julia Lawall
  2018-05-23 19:07   ` [PATCH 5/5] drm/rockchip: lvds: " Julia Lawall
  4 siblings, 0 replies; 66+ messages in thread
From: Julia Lawall @ 2018-05-23 19:07 UTC (permalink / raw)
  To: linux-arm-kernel

The device node iterators perform an of_node_get on each iteration, so a
jump out of the loop requires an of_node_put.

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

// <smpl>
@@
expression root,e;
local idexpression child;
iterator name for_each_child_of_node;
@@

 for_each_child_of_node(root, child) {
   ... when != of_node_put(child)
       when != e = child
+  of_node_put(child);
?  break;
   ...
}
... when != child
// </smpl>

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

---
 drivers/soc/ti/knav_dma.c |    1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/soc/ti/knav_dma.c b/drivers/soc/ti/knav_dma.c
index 224d7dd..bda3173 100644
--- a/drivers/soc/ti/knav_dma.c
+++ b/drivers/soc/ti/knav_dma.c
@@ -768,6 +768,7 @@ static int knav_dma_probe(struct platform_device *pdev)
 		ret = dma_init(node, child);
 		if (ret) {
 			dev_err(&pdev->dev, "init failed with %d\n", ret);
+			of_node_put(child);
 			break;
 		}
 	}


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

* [PATCH 4/5] pci/hotplug/pnv-php: add missing of_node_put
  2018-05-23 19:07 ` [PATCH 0/5] " Julia Lawall
                     ` (2 preceding siblings ...)
  2018-05-23 19:07   ` [PATCH 3/5] soc: ti: knav_dma: " Julia Lawall
@ 2018-05-23 19:07   ` Julia Lawall
  2018-05-23 21:50     ` Bjorn Helgaas
  2018-05-23 19:07   ` [PATCH 5/5] drm/rockchip: lvds: " Julia Lawall
  4 siblings, 1 reply; 66+ messages in thread
From: Julia Lawall @ 2018-05-23 19:07 UTC (permalink / raw)
  To: Benjamin Herrenschmidt
  Cc: kernel-janitors, Paul Mackerras, Michael Ellerman, Bjorn Helgaas,
	linuxppc-dev, linux-pci, linux-kernel

The device node iterators perform an of_node_get on each iteration, so a
jump out of the loop requires an of_node_put.

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

// <smpl>
@@
expression root,e;
local idexpression child;
iterator name for_each_child_of_node;
@@

 for_each_child_of_node(root, child) {
   ... when != of_node_put(child)
       when != e = child
+  of_node_put(child);
?  break;
   ...
}
... when != child
// </smpl>

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

---
 drivers/pci/hotplug/pnv_php.c |    8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/pci/hotplug/pnv_php.c b/drivers/pci/hotplug/pnv_php.c
index d441006..6c2e8d7 100644
--- a/drivers/pci/hotplug/pnv_php.c
+++ b/drivers/pci/hotplug/pnv_php.c
@@ -220,12 +220,16 @@ static int pnv_php_populate_changeset(struct of_changeset *ocs,
 
 	for_each_child_of_node(dn, child) {
 		ret = of_changeset_attach_node(ocs, child);
-		if (ret)
+		if (ret) {
+			of_node_put(child);
 			break;
+		}
 
 		ret = pnv_php_populate_changeset(ocs, child);
-		if (ret)
+		if (ret) {
+			of_node_put(child);
 			break;
+		}
 	}
 
 	return ret;


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

* [PATCH 5/5] drm/rockchip: lvds: add missing of_node_put
  2018-05-23 19:07 ` [PATCH 0/5] " Julia Lawall
                     ` (3 preceding siblings ...)
  2018-05-23 19:07   ` [PATCH 4/5] pci/hotplug/pnv-php: " Julia Lawall
@ 2018-05-23 19:07   ` Julia Lawall
  2018-06-16 12:24     ` Heiko Stübner
  4 siblings, 1 reply; 66+ messages in thread
From: Julia Lawall @ 2018-05-23 19:07 UTC (permalink / raw)
  To: Sandy Huang
  Cc: David Airlie, kernel-janitors, linux-kernel, dri-devel,
	linux-rockchip, linux-arm-kernel

The device node iterators perform an of_node_get on each iteration, so a
jump out of the loop requires an of_node_put.

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

// <smpl>
@@
expression root,e;
local idexpression child;
iterator name for_each_child_of_node;
@@

 for_each_child_of_node(root, child) {
   ... when != of_node_put(child)
       when != e = child
+  of_node_put(child);
?  break;
   ...
}
... when != child
// </smpl>

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

---
 drivers/gpu/drm/rockchip/rockchip_lvds.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/rockchip/rockchip_lvds.c b/drivers/gpu/drm/rockchip/rockchip_lvds.c
index e67f4ea..051b8be 100644
--- a/drivers/gpu/drm/rockchip/rockchip_lvds.c
+++ b/drivers/gpu/drm/rockchip/rockchip_lvds.c
@@ -363,8 +363,10 @@ static int rockchip_lvds_bind(struct device *dev, struct device *master,
 		of_property_read_u32(endpoint, "reg", &endpoint_id);
 		ret = drm_of_find_panel_or_bridge(dev->of_node, 1, endpoint_id,
 						  &lvds->panel, &lvds->bridge);
-		if (!ret)
+		if (!ret) {
+			of_node_put(endpoint);
 			break;
+		}
 	}
 	if (!child_count) {
 		DRM_DEV_ERROR(dev, "lvds port does not have any children\n");


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

* Re: [PATCH 4/5] pci/hotplug/pnv-php: add missing of_node_put
  2018-05-23 19:07   ` [PATCH 4/5] pci/hotplug/pnv-php: " Julia Lawall
@ 2018-05-23 21:50     ` Bjorn Helgaas
  0 siblings, 0 replies; 66+ messages in thread
From: Bjorn Helgaas @ 2018-05-23 21:50 UTC (permalink / raw)
  To: Julia Lawall
  Cc: Benjamin Herrenschmidt, kernel-janitors, Paul Mackerras,
	Michael Ellerman, Bjorn Helgaas, linuxppc-dev, linux-pci,
	linux-kernel

On Wed, May 23, 2018 at 09:07:15PM +0200, Julia Lawall wrote:
> The device node iterators perform an of_node_get on each iteration, so a
> jump out of the loop requires an of_node_put.
> 
> The semantic patch that fixes this problem is as follows
> (http://coccinelle.lip6.fr):
> 
> // <smpl>
> @@
> expression root,e;
> local idexpression child;
> iterator name for_each_child_of_node;
> @@
> 
>  for_each_child_of_node(root, child) {
>    ... when != of_node_put(child)
>        when != e = child
> +  of_node_put(child);
> ?  break;
>    ...
> }
> ... when != child
> // </smpl>
> 
> Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>

Applied to pci/hotplug for v4.18, thanks!

> ---
>  drivers/pci/hotplug/pnv_php.c |    8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/pci/hotplug/pnv_php.c b/drivers/pci/hotplug/pnv_php.c
> index d441006..6c2e8d7 100644
> --- a/drivers/pci/hotplug/pnv_php.c
> +++ b/drivers/pci/hotplug/pnv_php.c
> @@ -220,12 +220,16 @@ static int pnv_php_populate_changeset(struct of_changeset *ocs,
>  
>  	for_each_child_of_node(dn, child) {
>  		ret = of_changeset_attach_node(ocs, child);
> -		if (ret)
> +		if (ret) {
> +			of_node_put(child);
>  			break;
> +		}
>  
>  		ret = pnv_php_populate_changeset(ocs, child);
> -		if (ret)
> +		if (ret) {
> +			of_node_put(child);
>  			break;
> +		}
>  	}
>  
>  	return ret;
> 

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

* Re: [PATCH 1/5] pinctrl: at91-pio4: add missing of_node_put
  2018-05-23 19:07   ` [PATCH 1/5] pinctrl: at91-pio4: " Julia Lawall
@ 2018-05-24  7:59     ` Ludovic Desroches
  2018-05-24  8:30     ` Linus Walleij
  1 sibling, 0 replies; 66+ messages in thread
From: Ludovic Desroches @ 2018-05-24  7:59 UTC (permalink / raw)
  To: linux-arm-kernel

On Wed, May 23, 2018 at 09:07:12PM +0200, Julia Lawall wrote:
> The device node iterators perform an of_node_get on each iteration, so a
> jump out of the loop requires an of_node_put.
> 
> The semantic patch that fixes this problem is as follows
> (http://coccinelle.lip6.fr):
> 
> // <smpl>
> @@
> expression root,e;
> local idexpression child;
> iterator name for_each_child_of_node;
> @@
> 
>  for_each_child_of_node(root, child) {
>    ... when != of_node_put(child)
>        when != e = child
> +  of_node_put(child);
> ?  break;
>    ...
> }
> ... when != child
> // </smpl>
> 
> Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
Acked-by: Ludovic Desroches <ludovic.desroches@microchip.com>

Thanks
> 
> ---
>  drivers/pinctrl/pinctrl-at91-pio4.c |    4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/pinctrl/pinctrl-at91-pio4.c b/drivers/pinctrl/pinctrl-at91-pio4.c
> index 4b57a13..bafb3d4 100644
> --- a/drivers/pinctrl/pinctrl-at91-pio4.c
> +++ b/drivers/pinctrl/pinctrl-at91-pio4.c
> @@ -576,8 +576,10 @@ static int atmel_pctl_dt_node_to_map(struct pinctrl_dev *pctldev,
>  		for_each_child_of_node(np_config, np) {
>  			ret = atmel_pctl_dt_subnode_to_map(pctldev, np, map,
>  						    &reserved_maps, num_maps);
> -			if (ret < 0)
> +			if (ret < 0) {
> +				of_node_put(np);
>  				break;
> +			}
>  		}
>  	}
>  
> 

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

* Re: [PATCH 1/5] pinctrl: at91-pio4: add missing of_node_put
  2018-05-23 19:07   ` [PATCH 1/5] pinctrl: at91-pio4: " Julia Lawall
  2018-05-24  7:59     ` Ludovic Desroches
@ 2018-05-24  8:30     ` Linus Walleij
  1 sibling, 0 replies; 66+ messages in thread
From: Linus Walleij @ 2018-05-24  8:30 UTC (permalink / raw)
  To: linux-arm-kernel

On Wed, May 23, 2018 at 9:07 PM, Julia Lawall <Julia.Lawall@lip6.fr> wrote:

> The device node iterators perform an of_node_get on each iteration, so a
> jump out of the loop requires an of_node_put.
>
> The semantic patch that fixes this problem is as follows
> (http://coccinelle.lip6.fr):
>
> // <smpl>
> @@
> expression root,e;
> local idexpression child;
> iterator name for_each_child_of_node;
> @@
>
>  for_each_child_of_node(root, child) {
>    ... when != of_node_put(child)
>        when != e = child
> +  of_node_put(child);
> ?  break;
>    ...
> }
> ... when != child
> // </smpl>
>
> Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>

Patch applied with Ludovic's ACK!

Yours,
Linus Walleij

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

* Re: [PATCH 5/5] drm/rockchip: lvds: add missing of_node_put
  2018-05-23 19:07   ` [PATCH 5/5] drm/rockchip: lvds: " Julia Lawall
@ 2018-06-16 12:24     ` Heiko Stübner
  0 siblings, 0 replies; 66+ messages in thread
From: Heiko Stübner @ 2018-06-16 12:24 UTC (permalink / raw)
  To: Julia Lawall
  Cc: David Airlie, kernel-janitors, dri-devel, linux-kernel,
	linux-rockchip, linux-arm-kernel

Hi Julia,

Am Mittwoch, 23. Mai 2018, 21:07:16 CEST schrieb Julia Lawall:
> The device node iterators perform an of_node_get on each iteration, so a
> jump out of the loop requires an of_node_put.
> 
> The semantic patch that fixes this problem is as follows
> (http://coccinelle.lip6.fr):
> 
> // <smpl>
> @@
> expression root,e;
> local idexpression child;
> iterator name for_each_child_of_node;
> @@
> 
>  for_each_child_of_node(root, child) {
>    ... when != of_node_put(child)
>        when != e = child
> +  of_node_put(child);
> ?  break;
>    ...
> }
> ... when != child
> // </smpl>
> 
> Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>

thanks for catching this. I've added a "Fixes"-tag and
applied the patch to drm-misc-next 


Thanks
Heiko



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

end of thread, other threads:[~2018-06-16 12:24 UTC | newest]

Thread overview: 66+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-10-10 12:30 [PATCH 0/5] add missing of_node_put Julia Lawall
2015-10-10 12:30 ` [PATCH 1/5] backlight: 88pm860x_bl: " Julia Lawall
2015-10-13  8:15   ` Lee Jones
2015-10-10 12:30 ` [PATCH 2/5] power_supply: charger-manager: " Julia Lawall
2015-10-12  2:20   ` Krzysztof Kozlowski
2015-10-15  8:56   ` Sebastian Reichel
2015-10-10 12:30 ` [PATCH 3/5] ARM: shmobile: R-Mobile: " Julia Lawall
2015-10-12  0:16   ` Simon Horman
2015-10-12  7:18   ` Geert Uytterhoeven
2015-10-12  7:24     ` Julia Lawall
2015-10-12  7:26       ` Geert Uytterhoeven
2015-10-12  7:29     ` Thomas Petazzoni
2015-10-12  7:30       ` Geert Uytterhoeven
2015-10-10 12:30 ` [PATCH 4/5] regulator: of: " Julia Lawall
2015-10-12  0:33   ` Krzysztof Kozlowski
2015-10-12  5:35     ` Julia Lawall
2015-10-12 12:44     ` Julia Lawall
2015-10-12 12:58       ` Krzysztof Kozlowski
2018-02-12 12:09   ` Applied "regulator: of: Add a missing 'of_node_put()' in an error handling path of 'of_regulator_mat Mark Brown
2015-10-10 12:30 ` [PATCH 5/5] arm: add missing of_node_put Julia Lawall
2015-10-10 21:02   ` Arnd Bergmann
2015-10-10 21:08     ` Thomas Petazzoni
2015-10-10 21:12       ` Julia Lawall
2015-10-10 21:10     ` Julia Lawall
2015-10-10 21:15       ` Arnd Bergmann
2015-10-10 21:41         ` [PATCH 5/5 v2] " Julia Lawall
2015-10-21 20:41 ` [PATCH 0/5] " Julia Lawall
2015-10-21 20:41   ` [PATCH 1/5] clk: " Julia Lawall
2015-10-21 23:13     ` Stephen Boyd
2015-10-22  5:52       ` Julia Lawall
2015-10-21 20:41   ` [PATCH 2/5] clk: si5351: " Julia Lawall
2015-10-21 23:14     ` Stephen Boyd
2015-10-21 20:41   ` [PATCH 3/5] clk: imx27: " Julia Lawall
2015-10-21 23:15     ` Stephen Boyd
2015-10-21 20:41   ` [PATCH 4/5] clk: imx31: " Julia Lawall
2015-10-21 23:15     ` Stephen Boyd
2015-10-21 20:41   ` [PATCH 5/5] clk: scpi: " Julia Lawall
2015-10-21 23:17     ` Stephen Boyd
2015-10-22  9:21     ` Sudeep Holla
2015-11-26 17:29       ` Sudeep Holla
2015-12-01  0:28         ` Stephen Boyd
2015-12-01  0:29     ` Stephen Boyd
2015-12-21 16:39 ` [PATCH 0/5] " Julia Lawall
2015-12-21 16:39   ` [PATCH 1/5] pinctrl-tegra: " Julia Lawall
2015-12-22 12:44     ` Linus Walleij
2015-12-21 16:39   ` [PATCH 2/5] pinctrl: sirf: " Julia Lawall
2015-12-22 12:45     ` Linus Walleij
2015-12-21 16:39   ` [PATCH 3/5] pinctrl: sh-pfc: " Julia Lawall
2015-12-21 20:46     ` Laurent Pinchart
2015-12-22 12:47     ` Linus Walleij
2015-12-22 13:23       ` Geert Uytterhoeven
2015-12-21 16:39   ` [PATCH 4/5] pinctrl: rockchip: " Julia Lawall
2015-12-21 21:20     ` Heiko Stübner
2015-12-22 12:48     ` Linus Walleij
2015-12-21 16:39   ` [PATCH 5/5] pinctrl: mediatek: " Julia Lawall
2015-12-22 12:49     ` Linus Walleij
2018-05-23 19:07 ` [PATCH 0/5] " Julia Lawall
2018-05-23 19:07   ` [PATCH 1/5] pinctrl: at91-pio4: " Julia Lawall
2018-05-24  7:59     ` Ludovic Desroches
2018-05-24  8:30     ` Linus Walleij
2018-05-23 19:07   ` [PATCH 2/5] phy: " Julia Lawall
2018-05-23 19:07   ` [PATCH 3/5] soc: ti: knav_dma: " Julia Lawall
2018-05-23 19:07   ` [PATCH 4/5] pci/hotplug/pnv-php: " Julia Lawall
2018-05-23 21:50     ` Bjorn Helgaas
2018-05-23 19:07   ` [PATCH 5/5] drm/rockchip: lvds: " Julia Lawall
2018-06-16 12:24     ` Heiko Stübner

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).