linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/4] add missing of_node_put
@ 2015-11-18 22:04 Julia Lawall
  2015-11-18 22:04 ` [PATCH 2/4] mtd: nand: sunxi: " Julia Lawall
  0 siblings, 1 reply; 5+ messages in thread
From: Julia Lawall @ 2015-11-18 22:04 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/iio/adc/qcom-spmi-vadc.c     |    4 +++-
 drivers/mtd/nand/brcmnand/brcmnand.c |   14 ++++++++++----
 drivers/mtd/nand/sunxi_nand.c        |    4 +++-
 drivers/power/reset/at91-reset.c     |    1 +
 4 files changed, 17 insertions(+), 6 deletions(-)

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

* [PATCH 2/4] mtd: nand: sunxi: add missing of_node_put
  2015-11-18 22:04 [PATCH 0/4] add missing of_node_put Julia Lawall
@ 2015-11-18 22:04 ` Julia Lawall
  2015-11-23  7:26   ` Chen-Yu Tsai
                     ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Julia Lawall @ 2015-11-18 22:04 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.

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>

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

---
 drivers/mtd/nand/sunxi_nand.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/mtd/nand/sunxi_nand.c b/drivers/mtd/nand/sunxi_nand.c
index 2ed52e4..1bbcc0c 100644
--- a/drivers/mtd/nand/sunxi_nand.c
+++ b/drivers/mtd/nand/sunxi_nand.c
@@ -1391,8 +1391,10 @@ static int sunxi_nand_chips_init(struct device *dev, struct sunxi_nfc *nfc)
 
 	for_each_child_of_node(np, nand_np) {
 		ret = sunxi_nand_chip_init(dev, nfc, nand_np);
-		if (ret)
+		if (ret) {
+			of_node_put(nand_np);
 			return ret;
+		}
 	}
 
 	return 0;

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

* [PATCH 2/4] mtd: nand: sunxi: add missing of_node_put
  2015-11-18 22:04 ` [PATCH 2/4] mtd: nand: sunxi: " Julia Lawall
@ 2015-11-23  7:26   ` Chen-Yu Tsai
  2015-11-23 13:59   ` Boris Brezillon
  2015-12-01  1:56   ` Brian Norris
  2 siblings, 0 replies; 5+ messages in thread
From: Chen-Yu Tsai @ 2015-11-23  7:26 UTC (permalink / raw)
  To: linux-arm-kernel

On Thu, Nov 19, 2015 at 6:04 AM, Julia Lawall <Julia.Lawall@lip6.fr> 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>
>
> Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>

Acked-by: Chen-Yu Tsai <wens@csie.org>

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

* [PATCH 2/4] mtd: nand: sunxi: add missing of_node_put
  2015-11-18 22:04 ` [PATCH 2/4] mtd: nand: sunxi: " Julia Lawall
  2015-11-23  7:26   ` Chen-Yu Tsai
@ 2015-11-23 13:59   ` Boris Brezillon
  2015-12-01  1:56   ` Brian Norris
  2 siblings, 0 replies; 5+ messages in thread
From: Boris Brezillon @ 2015-11-23 13:59 UTC (permalink / raw)
  To: linux-arm-kernel

On Wed, 18 Nov 2015 23:04:12 +0100
Julia Lawall <Julia.Lawall@lip6.fr> 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>
> 
> Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>

Acked-by: Boris Brezillon <boris.brezillon@free-electrons.com>

Thanks,

Boris

-- 
Boris Brezillon, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com

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

* [PATCH 2/4] mtd: nand: sunxi: add missing of_node_put
  2015-11-18 22:04 ` [PATCH 2/4] mtd: nand: sunxi: " Julia Lawall
  2015-11-23  7:26   ` Chen-Yu Tsai
  2015-11-23 13:59   ` Boris Brezillon
@ 2015-12-01  1:56   ` Brian Norris
  2 siblings, 0 replies; 5+ messages in thread
From: Brian Norris @ 2015-12-01  1:56 UTC (permalink / raw)
  To: linux-arm-kernel

On Wed, Nov 18, 2015 at 11:04:12PM +0100, 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>
> 
> Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
> 

Pushed to l2-mtd.git

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

end of thread, other threads:[~2015-12-01  1:56 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-11-18 22:04 [PATCH 0/4] add missing of_node_put Julia Lawall
2015-11-18 22:04 ` [PATCH 2/4] mtd: nand: sunxi: " Julia Lawall
2015-11-23  7:26   ` Chen-Yu Tsai
2015-11-23 13:59   ` Boris Brezillon
2015-12-01  1:56   ` Brian Norris

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