cpufreq: s5pv210: add missing of_node_put()
authorJulia Lawall <Julia.Lawall@lip6.fr>
Fri, 21 Jul 2017 19:53:30 +0000 (21:53 +0200)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Wed, 26 Jul 2017 20:54:01 +0000 (22:54 +0200)
for_each_compatible_node performs an of_node_get on each iteration, so a
return from 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,e1,e2;
statement S;
iterator i1;
iterator name for_each_compatible_node;
@@

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

Additionally, call of_node_put on the previous value of np, obtained from
of_find_compatible_node, that is no longer accessible at the point of the
for_each_compatible_node.

Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
drivers/cpufreq/s5pv210-cpufreq.c

index f82074eea779ca40684cf98e8ab29a33b05f13b9..5d31c2db12a3f31b25d43be5eb73056a59d7415b 100644 (file)
@@ -602,6 +602,7 @@ static int s5pv210_cpufreq_probe(struct platform_device *pdev)
        }
 
        clk_base = of_iomap(np, 0);
+       of_node_put(np);
        if (!clk_base) {
                pr_err("%s: failed to map clock registers\n", __func__);
                return -EFAULT;
@@ -612,6 +613,7 @@ static int s5pv210_cpufreq_probe(struct platform_device *pdev)
                if (id < 0 || id >= ARRAY_SIZE(dmc_base)) {
                        pr_err("%s: failed to get alias of dmc node '%s'\n",
                                __func__, np->name);
+                       of_node_put(np);
                        return id;
                }
 
@@ -619,6 +621,7 @@ static int s5pv210_cpufreq_probe(struct platform_device *pdev)
                if (!dmc_base[id]) {
                        pr_err("%s: failed to map dmc%d registers\n",
                                __func__, id);
+                       of_node_put(np);
                        return -EFAULT;
                }
        }