Linux-Rockchip Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/5] add missing of_node_put
@ 2015-12-21 16:39 Julia Lawall
  2015-12-21 16:39 ` [PATCH 4/5] pinctrl: rockchip: " Julia Lawall
  0 siblings, 1 reply; 4+ messages in thread
From: Julia Lawall @ 2015-12-21 16:39 UTC (permalink / raw)
  To: linux-rockchip
  Cc: kernel-janitors, linux-arm-kernel, linux-kernel, linux-gpio,
	Linus Walleij, linux-sh, linux-mediatek

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] 4+ messages in thread

* [PATCH 4/5] pinctrl: rockchip: add missing of_node_put
  2015-12-21 16:39 [PATCH 0/5] add missing of_node_put Julia Lawall
@ 2015-12-21 16:39 ` Julia Lawall
       [not found]   ` <1450715988-4770-5-git-send-email-Julia.Lawall-L2FTfq7BK8M@public.gmane.org>
  2015-12-22 12:48   ` Linus Walleij
  0 siblings, 2 replies; 4+ messages in thread
From: Julia Lawall @ 2015-12-21 16:39 UTC (permalink / raw)
  To: Linus Walleij
  Cc: kernel-janitors, Heiko Stuebner, linux-gpio, linux-arm-kernel,
	linux-rockchip, 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-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] 4+ messages in thread

* Re: [PATCH 4/5] pinctrl: rockchip: add missing of_node_put
       [not found]   ` <1450715988-4770-5-git-send-email-Julia.Lawall-L2FTfq7BK8M@public.gmane.org>
@ 2015-12-21 21:20     ` Heiko Stübner
  0 siblings, 0 replies; 4+ messages in thread
From: Heiko Stübner @ 2015-12-21 21:20 UTC (permalink / raw)
  To: Julia Lawall
  Cc: linux-rockchip-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r, Linus Walleij,
	kernel-janitors-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	linux-gpio-u79uwXL29TY76Z2rM5mHXA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r

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-L2FTfq7BK8M@public.gmane.org>

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-4mtYJXux2i+zQB+pC5nmwQ@public.gmane.org>


Thanks
Heiko

^ permalink raw reply	[flat|nested] 4+ 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
       [not found]   ` <1450715988-4770-5-git-send-email-Julia.Lawall-L2FTfq7BK8M@public.gmane.org>
@ 2015-12-22 12:48   ` Linus Walleij
  1 sibling, 0 replies; 4+ messages in thread
From: Linus Walleij @ 2015-12-22 12:48 UTC (permalink / raw)
  To: Julia Lawall
  Cc: kernel-janitors, Heiko Stuebner, linux-gpio@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	open list:ARM/Rockchip SoC..., linux-kernel@vger.kernel.org

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] 4+ messages in thread

end of thread, other threads:[~2015-12-22 12:48 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-12-21 16:39 [PATCH 0/5] add missing of_node_put Julia Lawall
2015-12-21 16:39 ` [PATCH 4/5] pinctrl: rockchip: " Julia Lawall
     [not found]   ` <1450715988-4770-5-git-send-email-Julia.Lawall-L2FTfq7BK8M@public.gmane.org>
2015-12-21 21:20     ` Heiko Stübner
2015-12-22 12:48   ` Linus Walleij

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