* [PATCH v2] of: resolver: Add missing of_node_get and of_node_put
@ 2016-02-03 18:09 Amitoj Kaur Chawla
2016-02-11 23:18 ` Rob Herring
0 siblings, 1 reply; 3+ messages in thread
From: Amitoj Kaur Chawla @ 2016-02-03 18:09 UTC (permalink / raw)
To: pantelis.antoniou, robh+dt, frowand.list, grant.likely,
devicetree, linux-kernel
Cc: julia.lawall
In __of_find_node_by_full_name, add an of_node_get when detecting the
desired element, to ensure that it ends up with a reference count that is
one greater than on entering the function.
Also in __of_find_node_by_full_name, add an of_node_put on breaking
out of the for_each_child_of_node loop, to ensure that the reference
count of the returned value is not double incremented. This change
was made using Coccinelle.
The semantic patch used for this is as follows:
// <smpl>
@@
expression e;
local idexpression n;
@@
for_each_child_of_node(..., n) {
... when != of_node_put(n)
when != e = n
(
return n;
|
+ of_node_put(n);
? return ...;
)
...
}
// </smpl
Finally, add an of_node_put in for_each_child_of_node in the function
__of_adjust_phandle_ref after the value returned by
__of_find_node_by_full_name is no longer useful.
Signed-off-by: Amitoj Kaur Chawla <amitoj1606@gmail.com>
---
Changes in v2:
-Added an of_node_get and an extra of_node_put in the
functions __of_find_node_by_full_name and __of_adjust_phandle_ref
respectively.
drivers/of/resolver.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/drivers/of/resolver.c b/drivers/of/resolver.c
index 640eb4c..d313d49 100644
--- a/drivers/of/resolver.c
+++ b/drivers/of/resolver.c
@@ -36,12 +36,14 @@ static struct device_node *__of_find_node_by_full_name(struct device_node *node,
/* check */
if (of_node_cmp(node->full_name, full_name) == 0)
- return node;
+ return of_node_get(node);
for_each_child_of_node(node, child) {
found = __of_find_node_by_full_name(child, full_name);
- if (found != NULL)
+ if (found != NULL) {
+ of_node_put(child);
return found;
+ }
}
return NULL;
@@ -174,6 +176,7 @@ static int __of_adjust_phandle_ref(struct device_node *node,
if (of_prop_cmp(sprop->name, propstr) == 0)
break;
}
+ of_node_put(refnode);
if (!sprop) {
pr_err("%s: Could not find property '%s'\n",
--
1.9.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] of: resolver: Add missing of_node_get and of_node_put
2016-02-03 18:09 [PATCH v2] of: resolver: Add missing of_node_get and of_node_put Amitoj Kaur Chawla
@ 2016-02-11 23:18 ` Rob Herring
2016-02-12 7:58 ` Pantelis Antoniou
0 siblings, 1 reply; 3+ messages in thread
From: Rob Herring @ 2016-02-11 23:18 UTC (permalink / raw)
To: Amitoj Kaur Chawla
Cc: Pantelis Antoniou, Frank Rowand, Grant Likely,
devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
Julia Lawall
On Wed, Feb 3, 2016 at 12:09 PM, Amitoj Kaur Chawla
<amitoj1606-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
> In __of_find_node_by_full_name, add an of_node_get when detecting the
> desired element, to ensure that it ends up with a reference count that is
> one greater than on entering the function.
>
> Also in __of_find_node_by_full_name, add an of_node_put on breaking
> out of the for_each_child_of_node loop, to ensure that the reference
> count of the returned value is not double incremented. This change
> was made using Coccinelle.
Pantelis, are you convinced this is correct (albeit somewhat pointless)?
Rob
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] of: resolver: Add missing of_node_get and of_node_put
2016-02-11 23:18 ` Rob Herring
@ 2016-02-12 7:58 ` Pantelis Antoniou
0 siblings, 0 replies; 3+ messages in thread
From: Pantelis Antoniou @ 2016-02-12 7:58 UTC (permalink / raw)
To: Rob Herring
Cc: Amitoj Kaur Chawla, Frank Rowand, Grant Likely,
devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
Julia Lawall
Hi Rob,
> On Feb 12, 2016, at 01:18 , Rob Herring <robh+dt@kernel.org> wrote:
>
> On Wed, Feb 3, 2016 at 12:09 PM, Amitoj Kaur Chawla
> <amitoj1606@gmail.com> wrote:
>> In __of_find_node_by_full_name, add an of_node_get when detecting the
>> desired element, to ensure that it ends up with a reference count that is
>> one greater than on entering the function.
>>
>> Also in __of_find_node_by_full_name, add an of_node_put on breaking
>> out of the for_each_child_of_node loop, to ensure that the reference
>> count of the returned value is not double incremented. This change
>> was made using Coccinelle.
>
> Pantelis, are you convinced this is correct (albeit somewhat pointless)?
>
This is good enough. It’s a local method and we won’t ever try to use
it outside of the resolver. We need to fix the reference counting properly
sometime in the future.
> Rob
Regards
— Pantelis
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2016-02-12 7:58 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-02-03 18:09 [PATCH v2] of: resolver: Add missing of_node_get and of_node_put Amitoj Kaur Chawla
2016-02-11 23:18 ` Rob Herring
2016-02-12 7:58 ` Pantelis Antoniou
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).