2015-10-24 14:42:26

by Julia Lawall

[permalink] [raw]
Subject: [PATCH 0/9] add missing of_node_put

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/bluetooth/btmrvl_main.c | 5 ++++-
drivers/gpu/drm/tegra/dc.c | 4 +++-
drivers/gpu/host1x/bus.c | 4 +++-
drivers/leds/leds-88pm860x.c | 1 +
drivers/leds/leds-bcm6328.c | 4 +++-
drivers/leds/leds-bcm6358.c | 4 +++-
drivers/leds/leds-powernv.c | 8 ++++++--
drivers/pinctrl/pinctrl-at91.c | 5 ++++-
drivers/soc/ti/knav_qmss_queue.c | 3 +++
9 files changed, 30 insertions(+), 8 deletions(-)


2015-10-26 08:48:31

by Jacek Anaszewski

[permalink] [raw]
Subject: Re: [PATCH 0/9] add missing of_node_put

Hi Julia,

Patches 1-4 have been applied to the LED tree, thanks.

On 10/24/2015 04:42 PM, Julia Lawall wrote:
> 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):
>
[...]

--
Best Regards,
Jacek Anaszewski

2015-10-25 19:54:04

by Marcel Holtmann

[permalink] [raw]
Subject: Re: [PATCH 6/9] Bluetooth: btmrvl: add missing of_node_put

Hi Julia,

> for_each_compatible_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 e;
> local idexpression n;
> @@
>
> for_each_compatible_node(n, ...) {
> ... when != of_node_put(n)
> when != e = n
> (
> return n;
> |
> + of_node_put(n);
> ? return ...;
> )
> ...
> }
> // </smpl>
>
> Signed-off-by: Julia Lawall <[email protected]>
>
> ---
> drivers/bluetooth/btmrvl_main.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)

patch has been applied to bluetooth-next tree.

Regards

Marcel


2015-10-24 14:42:32

by Julia Lawall

[permalink] [raw]
Subject: [PATCH 6/9] Bluetooth: btmrvl: add missing of_node_put

for_each_compatible_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 e;
local idexpression n;
@@

for_each_compatible_node(n, ...) {
... when != of_node_put(n)
when != e = n
(
return n;
|
+ of_node_put(n);
? return ...;
)
...
}
// </smpl>

Signed-off-by: Julia Lawall <[email protected]>

---
drivers/bluetooth/btmrvl_main.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/bluetooth/btmrvl_main.c b/drivers/bluetooth/btmrvl_main.c
index 6ba2286..6af9173 100644
--- a/drivers/bluetooth/btmrvl_main.c
+++ b/drivers/bluetooth/btmrvl_main.c
@@ -516,14 +516,17 @@ static int btmrvl_check_device_tree(struct btmrvl_private *priv)
ret = of_property_read_u8_array(dt_node, "btmrvl,cal-data",
cal_data + BT_CAL_HDR_LEN,
BT_CAL_DATA_SIZE);
- if (ret)
+ if (ret) {
+ of_node_put(dt_node);
return ret;
+ }

BT_DBG("Use cal data from device tree");
ret = btmrvl_download_cal_data(priv, cal_data,
BT_CAL_DATA_SIZE);
if (ret) {
BT_ERR("Fail to download calibrate data");
+ of_node_put(dt_node);
return ret;
}
}