* [PATCH] leds: tlc591xx: add missing of_node_put
@ 2017-07-15 7:48 Julia Lawall
2017-07-15 9:02 ` Pavel Machek
0 siblings, 1 reply; 3+ messages in thread
From: Julia Lawall @ 2017-07-15 7:48 UTC (permalink / raw)
To: Richard Purdie
Cc: kernel-janitors, Jacek Anaszewski, Pavel Machek, linux-leds,
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.
The semantic patch that fixes this problem is as follows
(http://coccinelle.lip6.fr):
// <smpl>
@@
local idexpression n;
expression e,e1;
iterator name for_each_child_of_node;
@@
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/leds/leds-tlc591xx.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff -u -p a/drivers/leds/leds-tlc591xx.c b/drivers/leds/leds-tlc591xx.c
--- a/drivers/leds/leds-tlc591xx.c
+++ b/drivers/leds/leds-tlc591xx.c
@@ -230,12 +230,18 @@ tlc591xx_probe(struct i2c_client *client
for_each_child_of_node(np, child) {
err = of_property_read_u32(child, "reg", ®);
- if (err)
+ if (err) {
+ of_node_put(child);
return err;
- if (reg < 0 || reg >= tlc591xx->max_leds)
+ }
+ if (reg < 0 || reg >= tlc591xx->max_leds) {
+ of_node_put(child);
return -EINVAL;
- if (priv->leds[reg].active)
+ }
+ if (priv->leds[reg].active) {
+ of_node_put(child);
return -EINVAL;
+ }
priv->leds[reg].active = true;
priv->leds[reg].ldev.name =
of_get_property(child, "label", NULL) ? : child->name;
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] leds: tlc591xx: add missing of_node_put
2017-07-15 7:48 [PATCH] leds: tlc591xx: add missing of_node_put Julia Lawall
@ 2017-07-15 9:02 ` Pavel Machek
2017-07-15 9:09 ` Julia Lawall
0 siblings, 1 reply; 3+ messages in thread
From: Pavel Machek @ 2017-07-15 9:02 UTC (permalink / raw)
To: Julia Lawall
Cc: Richard Purdie, kernel-janitors, Jacek Anaszewski, linux-leds,
linux-kernel
[-- Attachment #1: Type: text/plain, Size: 1411 bytes --]
On Sat 2017-07-15 09:48:53, Julia Lawall 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.
>
> The semantic patch that fixes this problem is as follows
> (http://coccinelle.lip6.fr):
>
> // <smpl>
> @@
> local idexpression n;
> expression e,e1;
> iterator name for_each_child_of_node;
> @@
>
> 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>
Acked-by: Pavel Machek <pavel@ucw.cz>
> @@ -230,12 +230,18 @@ tlc591xx_probe(struct i2c_client *client
>
> for_each_child_of_node(np, child) {
> err = of_property_read_u32(child, "reg", ®);
> - if (err)
> + if (err) {
> + of_node_put(child);
> return err;
> - if (reg < 0 || reg >= tlc591xx->max_leds)
> + }
> + if (reg < 0 || reg >= tlc591xx->max_leds) {
> + of_node_put(child);
> return -EINVAL;
> - if (priv->leds[reg].active)
> + }
> + if (priv->leds[reg].active) {
> + of_node_put(child);
> return -EINVAL;
> + }
I'd combine last two if()s into one...
Pavel
--
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 181 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] leds: tlc591xx: add missing of_node_put
2017-07-15 9:02 ` Pavel Machek
@ 2017-07-15 9:09 ` Julia Lawall
0 siblings, 0 replies; 3+ messages in thread
From: Julia Lawall @ 2017-07-15 9:09 UTC (permalink / raw)
To: Pavel Machek
Cc: Richard Purdie, kernel-janitors, Jacek Anaszewski, linux-leds,
linux-kernel
On Sat, 15 Jul 2017, Pavel Machek wrote:
> On Sat 2017-07-15 09:48:53, Julia Lawall 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.
> >
> > The semantic patch that fixes this problem is as follows
> > (http://coccinelle.lip6.fr):
> >
> > // <smpl>
> > @@
> > local idexpression n;
> > expression e,e1;
> > iterator name for_each_child_of_node;
> > @@
> >
> > 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>
>
> Acked-by: Pavel Machek <pavel@ucw.cz>
>
> > @@ -230,12 +230,18 @@ tlc591xx_probe(struct i2c_client *client
> >
> > for_each_child_of_node(np, child) {
> > err = of_property_read_u32(child, "reg", ®);
> > - if (err)
> > + if (err) {
> > + of_node_put(child);
> > return err;
> > - if (reg < 0 || reg >= tlc591xx->max_leds)
> > + }
> > + if (reg < 0 || reg >= tlc591xx->max_leds) {
> > + of_node_put(child);
> > return -EINVAL;
> > - if (priv->leds[reg].active)
> > + }
> > + if (priv->leds[reg].active) {
> > + of_node_put(child);
> > return -EINVAL;
> > + }
>
> I'd combine last two if()s into one...
The test won't all fit on one line. Should I do it anyway?
julia
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-07-15 9:09 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-07-15 7:48 [PATCH] leds: tlc591xx: add missing of_node_put Julia Lawall
2017-07-15 9:02 ` Pavel Machek
2017-07-15 9:09 ` Julia Lawall
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox