Add of_node_put to avoid memory leak
Subsystems (6)
cover Add of_node_put to avoid memory leak
These patches introduce calls to of_node_put after various functions that call of_node_get.
PATCH 1/7 drivers/macintosh/via-pmu-led.c: Add of_node_put to avoid memory leak
Add a call to of_node_put in the error handling code following a call to of_find_node_by_path.
The semantic match that finds this problem is as follows:
(http://coccinelle.lip6.fr/)
// <smpl>
@r exists@
local idexpression x;
expression E,E1;
statement S;
@@
*x =
(of_find_node_by_path
|of_find_node_by_name |of_find_node_by_phandle |of_get_parent |of_get_next_parent |of_get_next_child |of_find_compatible_node |of_match_node
)(...);
...
if (x = NULL) S
<... when != x = E
*if (...) {
... when != of_node_put(x)
when != if (...) { ... of_node_put(x); ... }(
return <+...x...+>;
|
* return ...;
)
}
...>of_node_put(x);
// </smpl>
--- drivers/macintosh/via-pmu-led.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/macintosh/via-pmu-led.c +3 -1
@@ -92,8 +92,10 @@ static int __init via_pmu_led_init(void)if (dt =NULL )return -ENODEV ; model =of_get_property (dt,"model" ,NULL ); -if (model =NULL ) +if (model =NULL ) { +of_node_put (dt);return -ENODEV ; + } if (strncmp(model, "PowerBook", strlen("PowerBook")) != 0 && strncmp(model, "iBook", strlen("iBook")) != 0 && strcmp(model, "PowerMac7,2") != 0 &&
Re: [PATCH 1/7] drivers/macintosh/via-pmu-led.c: Add of_node_put to avoid memory leak
Quoted 52 lines · Julia Lawall
Add a call to
of_node_putin the error handling code following a call toof_find_node_by_path.The semantic match that finds this problem is as follows:
(http://coccinelle.lip6.fr/)// <smpl>
@r exists@
local idexpression x;
expression E,E1;
statement S;
@@*x =
(of_find_node_by_path|of_find_node_by_name |of_find_node_by_phandle |of_get_parent |of_get_next_parent |of_get_next_child |of_find_compatible_node |of_match_node)(...);
...
if (x = NULL) S
<... when != x = E
*if (...) {
... when !=of_node_put(x)when != if (...) { ... of_node_put(x); ... }(
return <+...x...+>;
|
* return ...;
)
}
...>of_node_put(x);
// </smpl>Signed-off-by Julia Lawall <[email protected]>--- drivers/macintosh/via-pmu-led.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/macintosh/via-pmu-led.c +0
-0@@ -92,8 +92,10 @@ static int __init via_pmu_led_init(void)if (dt =NULL )
drivers/macintosh/via-pmu-led.c static int __init via_pmu_led_init(void) · line 101
Quoted 10 lines
drivers/macintosh/via-pmu-led.c +3
-1return -ENODEV ; model =of_get_property (dt,"model" ,NULL ); -if (model =NULL ) +if (model =NULL ) { +of_node_put (dt);return -ENODEV ; + } if (strncmp(model, "PowerBook", strlen("PowerBook")) != 0 && strncmp(model, "iBook", strlen("iBook")) != 0 && strcmp(model, "PowerMac7,2") != 0 &&
is there any rule that says when to use strncmp ? it seems perfecly valid to use strcpy here (what is done in the last cmp).
re,
wh
Re: [PATCH 1/7] drivers/macintosh/via-pmu-led.c: Add of_node_put to avoid memory leak
Quoted 60 lines · walter harms
Quoted 57 lines · Julia Lawall
Add a call to
of_node_putin the error handling code following a call toof_find_node_by_path.The semantic match that finds this problem is as follows:
(http://coccinelle.lip6.fr/)// <smpl>
@r exists@
local idexpression x;
expression E,E1;
statement S;
@@*x =
(of_find_node_by_path|of_find_node_by_name |of_find_node_by_phandle |of_get_parent |of_get_next_parent |of_get_next_child |of_find_compatible_node |of_match_node)(...);
...
if (x = NULL) S
<... when != x = E
*if (...) {
... when !=of_node_put(x)when != if (...) { ... of_node_put(x); ... }(
return <+...x...+>;
|
* return ...;
)
}
...>of_node_put(x);
// </smpl>Signed-off-by Julia Lawall <[email protected]>--- drivers/macintosh/via-pmu-led.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/macintosh/via-pmu-led.c +2
-1@@ -92,8 +92,10 @@ static int __init via_pmu_led_init(void)if (dt =NULL )return -ENODEV ; model =of_get_property (dt,"model" ,NULL ); -if (model =NULL ) +if (model =NULL ) { +of_node_put (dt);return -ENODEV ;
Quoted 8 lines
drivers/macintosh/via-pmu-led.c static int __init via_pmu_led_init(void) · line 101
Quoted 5 lines
drivers/macintosh/via-pmu-led.c +1
-0+ } if (strncmp(model, "PowerBook", strlen("PowerBook")) != 0 && strncmp(model, "iBook", strlen("iBook")) != 0 && strcmp(model, "PowerMac7,2") != 0 &&is there any rule that says when to use strncmp ? it seems perfecly valid to use strcpy here (what is done in the last cmp).
Perhaps there are some characters after eg PowerBook that one doesn't want to compare with?
julia
Re: [PATCH 1/7] drivers/macintosh/via-pmu-led.c: Add of_node_put to avoid memory leak
Quoted 18 lines · Julia Lawall
Quoted 8 lines · walter harms
Quoted 8 lines
drivers/macintosh/via-pmu-led.c +2
-1@@ -92,8 +92,10 @@ static int __init via_pmu_led_init(void)if (dt =NULL )return -ENODEV ; model =of_get_property (dt,"model" ,NULL ); -if (model =NULL ) +if (model =NULL ) { +of_node_put (dt);return -ENODEV ;Quoted 8 lines
drivers/macintosh/via-pmu-led.c static int __init via_pmu_led_init(void) · line 101
Quoted 5 lines
drivers/macintosh/via-pmu-led.c +1
-0+ } if (strncmp(model, "PowerBook", strlen("PowerBook")) != 0 && strncmp(model, "iBook", strlen("iBook")) != 0 && strcmp(model, "PowerMac7,2") != 0 &&is there any rule that says when to use strncmp ? it seems perfecly valid to use strcpy here (what is done in the last cmp).
Quoted 2 lines
Perhaps there are some characters after eg PowerBook that one doesn't want to compare with?
Yes. The model property on powermacs always has the version number. strncmp makes sure that *all* PowerBooks and iBooks are matched.
g.
Re: [PATCH 1/7] drivers/macintosh/via-pmu-led.c: Add of_node_put to avoid memory leak
In reply to Julia LawallQuoted 7 lines · Julia Lawall
Quoted 5 lines · walter harms
Quoted 2 lines · Julia Lawall
Add a call to
of_node_putin the error handling code following a call toof_find_node_by_path.
[...]
Quoted 19 lines
Quoted 10 lines
Quoted 10 lines
drivers/macintosh/via-pmu-led.c +2
-1@@ -92,8 +92,10 @@ static int __init via_pmu_led_init(void)if (dt =NULL )return -ENODEV ; model =of_get_property (dt,"model" ,NULL ); -if (model =NULL ) +if (model =NULL ) { +of_node_put (dt);return -ENODEV ;Quoted 8 lines
drivers/macintosh/via-pmu-led.c static int __init via_pmu_led_init(void) · line 101
Quoted 5 lines
drivers/macintosh/via-pmu-led.c +1
-0+ } if (strncmp(model, "PowerBook", strlen("PowerBook")) != 0 && strncmp(model, "iBook", strlen("iBook")) != 0 && strcmp(model, "PowerMac7,2") != 0 &&is there any rule that says when to use strncmp ? it seems perfecly valid to use strcpy here (what is done in the last cmp).
Quoted 2 lines
Perhaps there are some characters after eg PowerBook that one doesn't want to compare with?
It seems to me that model has no '\0' in the end. If model is got from the hardware then we should double check it - maybe harware is buggy. Otherwise we'll overflow model.
But why strcmp(model, "PowerMac7,2")? IMO it should be replaced with strncmp().
Signature · 1 line
Vasiliy
Re: [PATCH 1/7] drivers/macintosh/via-pmu-led.c: Add of_node_put to avoid memory leak
Quoted 10 lines · Vasiliy Kulikov
Quoted 9 lines · Julia Lawall
Quoted 7 lines · walter harms
Quoted 4 lines
if (
strncmp(model, "PowerBook", strlen("PowerBook"))!= 0 &&strncmp(model, "iBook", strlen("iBook"))!= 0 &&strcmp(model, "PowerMac7,2")!= 0 &&is there any rule that says when to use strncmp ? it seems perfecly valid to use strcpy here (what is done in the last cmp).
Quoted 6 lines
Quoted 2 lines
Perhaps there are some characters after eg PowerBook that one doesn't want to compare with?
It seems to me that model has no '\0' in the end. If model is got from the hardware then we should double check it - maybe harware is buggy. Otherwise we'll overflow model.
Model does have \0 at the end. This code is using strncmp to purposefully ignore the model suffix.
Quoted 2 lines
But why
strcmp(model, "PowerMac7,2")? IMO it should be replaced withstrncmp().
We use strcmp when parsing the device tree because the the length of the model property string is unknown and in most cases we *must* match the exact entire string, such as with this PowerMac7,2 example. Using strncmp would also happen to match with something like "PowerMac7,2345" which is not the desired behaviour.
g.
--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 1/7] drivers/macintosh/via-pmu-led.c: Add of_node_put to avoid memory leak
Quoted 18 lines · Grant Likely
Quoted 6 lines · Vasiliy Kulikov
Quoted 5 lines · Julia Lawall
Quoted 4 lines · walter harms
Quoted 4 lines
if (
strncmp(model, "PowerBook", strlen("PowerBook"))!= 0 &&strncmp(model, "iBook", strlen("iBook")) != 0 && strcmp(model, "PowerMac7,2") != 0 &&Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
is there any rule that says when to use strncmp ? it seems perfecly valid to use strcpy here (what is done in the last cmp).
Perhaps there are some characters after eg PowerBook that one doesn't want to compare with?
It seems to me that model has no '\0' in the end. If model is got from the hardware then we should double check it - maybe harware is buggy. Otherwise we'll overflow model.
Model does have \0 at the end. This code is using strncmp to purposefully ignore the model suffix.
Quoted 9 lines
Quoted 2 lines
But why
strcmp(model, "PowerMac7,2")? IMO it should be replaced withstrncmp().We use strcmp when parsing the device tree because the the length of the model property string is unknown and in most cases we *must* match the exact entire string, such as with this PowerMac7,2 example. Using strncmp would also happen to match with something like "PowerMac7,2345" which is not the desired behaviour.
hi Grant,
whould you mind to use you explanation as comment in the code ?
Tthat the strncpy/strcpy difference is important should be noted. that would be clearly a bonos with further audits.
re,
wh
PATCH 2/7 drivers/serial/mpc52xx_uart.c: Add of_node_put to avoid memory leak
In reply to Julia LawallAdd a call to of_node_put in the error handling code following a call to of_find_compatible_node.
The semantic match that finds this problem is as follows:
(http://coccinelle.lip6.fr/)
// <smpl>
@r exists@
local idexpression x;
expression E,E1;
statement S;
@@
*x =
(of_find_node_by_path
|of_find_node_by_name |of_find_node_by_phandle |of_get_parent |of_get_next_parent |of_get_next_child |of_find_compatible_node |of_match_node
)(...);
...
if (x = NULL) S
<... when != x = E
*if (...) {
... when != of_node_put(x)
when != if (...) { ... of_node_put(x); ... }(
return <+...x...+>;
|
* return ...;
)
}
...>of_node_put(x);
// </smpl>
--- drivers/serial/mpc52xx_uart.c | 1 + 1 file changed, 1 insertion(+)
drivers/serial/mpc52xx_uart.c +1 -0
@@ -500,6 +500,7 @@ static int __init mpc512x_psc_fifoc_init(void) psc_fifoc =of_iomap (np,0 );if (!psc_fifoc) {pr_err ("%s: Can't map FIFOC\n" , __func__); +of_node_put (np);return -ENODEV ; }
Re: [PATCH 2/7] drivers/serial/mpc52xx_uart.c: Add of_node_put to avoid memory leak
Quoted 39 lines · Julia Lawall
Add a call to
of_node_putin the error handling code following a call toof_find_compatible_node.The semantic match that finds this problem is as follows:
(http://coccinelle.lip6.fr/)// <smpl>
@r exists@
local idexpression x;
expression E,E1;
statement S;
@@*x =
(of_find_node_by_path|of_find_node_by_name |of_find_node_by_phandle |of_get_parent |of_get_next_parent |of_get_next_child |of_find_compatible_node |of_match_node)(...);
...
if (x == NULL) S
<... when != x = E
*if (...) {
... when !=of_node_put(x)when != if (...) { ... of_node_put(x); ... }(
return <+...x...+>;
|
* return ...;
)
}
...>of_node_put(x);
// </smpl>
Quoted 1 line
Signed-off-by Julia Lawall <[email protected]>
adding ppc-list to CC.
Quoted 23 lines
--- drivers/serial/mpc52xx_uart.c | 1 + 1 file changed, 1 insertion(+)drivers/serial/mpc52xx_uart.c +1
-1@@ -500,6 +500,7 @@ static int __init mpc512x_psc_fifoc_init(void) psc_fifoc =of_iomap (np,0 );if (!psc_fifoc) {pr_err ("%s: Can't map FIFOC\n" , __func__); +of_node_put (np);return -ENODEV ; } --To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Signature · 2 lines
Pengutronix e.K. | Wolfram Sang | Industrial Linux Solutions | http://www.pengutronix.de/ |
PATCH 3/7 drivers/mtd/nand/mpc5121_nfc.c: Add of_node_put to avoid memory leak
In reply to Julia LawallAdd a call to of_node_put in the error handling code following a call to of_find_compatible_node.
The semantic match that finds this problem is as follows:
(http://coccinelle.lip6.fr/)
// <smpl>
@r exists@
local idexpression x;
expression E,E1;
statement S;
@@
*x =
(of_find_node_by_path
|of_find_node_by_name |of_find_node_by_phandle |of_get_parent |of_get_next_parent |of_get_next_child |of_find_compatible_node |of_match_node
)(...);
...
if (x = NULL) S
<... when != x = E
*if (...) {
... when != of_node_put(x)
when != if (...) { ... of_node_put(x); ... }(
return <+...x...+>;
|
* return ...;
)
}
...>of_node_put(x);
// </smpl>
--- drivers/mtd/nand/mpc5121_nfc.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/mtd/nand/mpc5121_nfc.c +5 -2
@@ -568,6 +568,7 @@ static int mpc5121_nfc_read_hw_config(struct mtd_info *mtd)uint rcw_width;uint rcwh;uint romloc, ps; +int ret =0 ; rmnode =of_find_compatible_node (NULL ,NULL ,"fsl,mpc5121-reset" );if (!rmnode) {
@@ -579,7 +580,8 @@ static int mpc5121_nfc_read_hw_config(struct mtd_info *mtd) rm =of_iomap (rmnode,0 );if (!rm) {dev_err (prv->dev,"Error mapping reset module node!\n" ); -return -EBUSY ; + ret = -EBUSY ; + goto out; } rcwh =in_be32 (&rm->rcwhr);
@@ -628,8 +630,9 @@ static int mpc5121_nfc_read_hw_config(struct mtd_info *mtd) rcw_width *8 , rcw_pagesize, rcw_sparesize);iounmap (rm); +out:of_node_put (rmnode); -return 0 ; +return ret; }/* Free driver resources */
Re: [PATCH 3/7] drivers/mtd/nand/mpc5121_nfc.c: Add of_node_put to avoid memory leak
Quoted 39 lines · Julia Lawall
Add a call to
of_node_putin the error handling code following a call toof_find_compatible_node.The semantic match that finds this problem is as follows:
(http://coccinelle.lip6.fr/)// <smpl>
@r exists@
local idexpression x;
expression E,E1;
statement S;
@@*x =
(of_find_node_by_path|of_find_node_by_name |of_find_node_by_phandle |of_get_parent |of_get_next_parent |of_get_next_child |of_find_compatible_node |of_match_node)(...);
...
if (x == NULL) S
<... when != x = E
*if (...) {
... when !=of_node_put(x)when != if (...) { ... of_node_put(x); ... }(
return <+...x...+>;
|
* return ...;
)
}
...>of_node_put(x);
// </smpl>
Quoted 1 line
Signed-off-by Julia Lawall <[email protected]>
adding ppc-list to cc.
Quoted 43 lines
--- drivers/mtd/nand/mpc5121_nfc.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)drivers/mtd/nand/mpc5121_nfc.c +5
-2@@ -568,6 +568,7 @@ static int mpc5121_nfc_read_hw_config(struct mtd_info *mtd)uint rcw_width;uint rcwh;uint romloc, ps; +int ret =0 ; rmnode =of_find_compatible_node (NULL ,NULL ,"fsl,mpc5121-reset" );if (!rmnode) {@@ -579,7 +580,8 @@ static int mpc5121_nfc_read_hw_config(struct mtd_info *mtd) rm =of_iomap (rmnode,0 );if (!rm) {dev_err (prv->dev,"Error mapping reset module node!\n" ); -return -EBUSY ; + ret = -EBUSY ; + goto out; } rcwh =in_be32 (&rm->rcwhr);@@ -628,8 +630,9 @@ static int mpc5121_nfc_read_hw_config(struct mtd_info *mtd) rcw_width *8 , rcw_pagesize, rcw_sparesize);iounmap (rm); +out:of_node_put (rmnode); -return 0 ; +return ret; }/* Free driver resources */ _______________________________________________
devicetree-discuss mailing list
[email protected]
https://lists.ozlabs.org/listinfo/devicetree-discuss
Signature · 2 lines
Pengutronix e.K. | Wolfram Sang | Industrial Linux Solutions | http://www.pengutronix.de/ |
Artem Bityutskiy
AppliedRe: [PATCH 3/7] drivers/mtd/nand/mpc5121_nfc.c: Add of_node_put to avoid memory leak
In reply to Julia LawallQuoted 5 lines · Julia Lawall
Add a call to
of_node_putin the error handling code following a call toof_find_compatible_node.The semantic match that finds this problem is as follows:
(http://coccinelle.lip6.fr/)
Pushed to l2-mtd-2.6.git / master, thanks.
Signature · 2 lines
Best Regards, Artem Bityutskiy (Битюцкий Артём)
PATCH 4/7 arch/powerpc/platforms/powermac/pfunc_core.c: Add of_node_put to avoid memory leak
In reply to Julia LawallAdd a call to of_node_put in the error handling code following a call to of_find_node_by_phandle.
The semantic match that finds this problem is as follows:
(http://coccinelle.lip6.fr/)
// <smpl>
@r exists@
local idexpression x;
expression E,E1;
statement S;
@@
*x =
(of_find_node_by_path
|of_find_node_by_name |of_find_node_by_phandle |of_get_parent |of_get_next_parent |of_get_next_child |of_find_compatible_node |of_match_node
)(...);
...
if (x = NULL) S
<... when != x = E
*if (...) {
... when != of_node_put(x)
when != if (...) { ... of_node_put(x); ... }(
return <+...x...+>;
|
* return ...;
)
}
...>of_node_put(x);
// </smpl>
--- arch/powerpc/platforms/powermac/pfunc_core.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
arch/powerpc/platforms/powermac/pfunc_core.c +6 -3
@@ -837,8 +837,10 @@ struct pmf_function *__pmf_find_function(struct device_node *target,return NULL ; find_it: dev =pmf_find_device (actor); -if (dev =NULL ) -return NULL ; +if (dev =NULL ) { + result =NULL ; + goto out; + }list_for_each_entry (func, &dev->functions, link) {if (name &&strcmp (name, func->name))
@@ -850,8 +852,9 @@ struct pmf_function *__pmf_find_function(struct device_node *target, result = func;break ; } -of_node_put (actor);pmf_put_device (dev); +out: +of_node_put (actor);return result; }
Re: [PATCH 4/7] arch/powerpc/platforms/powermac/pfunc_core.c: Add of_node_put to avoid memory leak
[cc'ing linuxppc-dev]
Quoted 39 lines · Julia Lawall
Add a call to
of_node_putin the error handling code following a call toof_find_node_by_phandle.The semantic match that finds this problem is as follows:
(http://coccinelle.lip6.fr/)// <smpl>
@r exists@
local idexpression x;
expression E,E1;
statement S;
@@*x =
(of_find_node_by_path|of_find_node_by_name |of_find_node_by_phandle |of_get_parent |of_get_next_parent |of_get_next_child |of_find_compatible_node |of_match_node)(...);
...
if (x = NULL) S
<... when != x = E
*if (...) {
... when !=of_node_put(x)when != if (...) { ... of_node_put(x); ... }(
return <+...x...+>;
|
* return ...;
)
}
...>of_node_put(x);
// </smpl>
Quoted 1 line
Signed-off-by Julia Lawall <[email protected]>
Quoted 34 lines
--- arch/powerpc/platforms/powermac/pfunc_core.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)arch/powerpc/platforms/powermac/pfunc_core.c +6
-3@@ -837,8 +837,10 @@ struct pmf_function *__pmf_find_function(struct device_node *target,return NULL ; find_it: dev =pmf_find_device (actor); -if (dev =NULL ) -return NULL ; +if (dev =NULL ) { + result =NULL ; + goto out; + }list_for_each_entry (func, &dev->functions, link) {if (name &&strcmp (name, func->name))@@ -850,8 +852,9 @@ struct pmf_function *__pmf_find_function(struct device_node *target, result = func;break ; } -of_node_put (actor);pmf_put_device (dev); +out: +of_node_put (actor);return result; }
PATCH 5/7 arch/powerpc/sysdev/qe_lib/qe.c: Add of_node_put to avoid memory leak
In reply to Julia LawallAdd a call to of_node_put in the error handling code following a call to of_find_compatible_node.
The semantic match that finds this problem is as follows:
(http://coccinelle.lip6.fr/)
// <smpl>
@r exists@
local idexpression x;
expression E,E1;
statement S;
@@
*x =
(of_find_node_by_path
|of_find_node_by_name |of_find_node_by_phandle |of_get_parent |of_get_next_parent |of_get_next_child |of_find_compatible_node |of_match_node
)(...);
...
if (x = NULL) S
<... when != x = E
*if (...) {
... when != of_node_put(x)
when != if (...) { ... of_node_put(x); ... }(
return <+...x...+>;
|
* return ...;
)
}
...>of_node_put(x);
// </smpl>
--- arch/powerpc/sysdev/qe_lib/qe.c | 1 + 1 file changed, 1 insertion(+)
arch/powerpc/sysdev/qe_lib/qe.c +1 -0
@@ -640,6 +640,7 @@ unsigned int qe_get_num_of_snums(void)if ((num_of_snums <28 ) || (num_of_snums >QE_NUM_OF_SNUM )) {/* No QE ever has fewer than 28 SNUMs */ pr_err ("QE: number of snum is invalid\n" ); +of_node_put (qe);return -EINVAL ; } }
Re: [PATCH 5/7] arch/powerpc/sysdev/qe_lib/qe.c: Add of_node_put to avoid memory leak
Quoted 2 lines · Julia Lawall
Add a call to
of_node_putin the error handling code following a call toof_find_compatible_node.
Thanks, Julia. Your work in finding these kinds of bugs is very much appreciated.
Kumar Gala
AppliedRe: [PATCH 5/7] arch/powerpc/sysdev/qe_lib/qe.c: Add of_node_put to avoid memory leak
In reply to Julia LawallQuoted 39 lines · Julia Lawall
Add a call to
of_node_putin the error handling code following a call toof_find_compatible_node.The semantic match that finds this problem is as follows:
(http://coccinelle.lip6.fr/)// <smpl>
@r exists@
local idexpression x;
expression E,E1;
statement S;
@@*x =
(of_find_node_by_path|of_find_node_by_name |of_find_node_by_phandle |of_get_parent |of_get_next_parent |of_get_next_child |of_find_compatible_node |of_match_node)(...);
...
if (x = NULL) S
<... when != x = E
*if (...) {
... when !=of_node_put(x)when != if (...) { ... of_node_put(x); ... }(
return <+...x...+>;
|
* return ...;
)
}
...>of_node_put(x);
// </smpl>
Quoted 5 lines
Signed-off-by Julia Lawall <[email protected]>---
arch/powerpc/sysdev/qe_lib/qe.c| 1 +1 file changed, 1 insertion(+)
applied to merge
- k
PATCH 6/7 arch/powerpc/platforms/maple/setup.c: Add of_node_put to avoid memory leak
In reply to Julia LawallAdd a call to of_node_put in the error handling code following a call to of_find_node_by_path.
The semantic match that finds this problem is as follows:
(http://coccinelle.lip6.fr/)
// <smpl>
@r exists@
local idexpression x;
expression E,E1;
statement S;
@@
*x =
(of_find_node_by_path
|of_find_node_by_name |of_find_node_by_phandle |of_get_parent |of_get_next_parent |of_get_next_child |of_find_compatible_node |of_match_node
)(...);
...
if (x = NULL) S
<... when != x = E
*if (...) {
... when != of_node_put(x)
when != if (...) { ... of_node_put(x); ... }(
return <+...x...+>;
|
* return ...;
)
}
...>of_node_put(x);
// </smpl>
--- arch/powerpc/platforms/maple/setup.c | 1 + 1 file changed, 1 insertion(+)
arch/powerpc/platforms/maple/setup.c +1 -0
@@ -358,6 +358,7 @@ static int __init maple_cpc925_edac_setup(void) model = (const unsigned char *)of_get_property (np,"model" ,NULL );if (!model) {printk (KERN_ERR "%s: Unabel to get model info\n" , __func__); +of_node_put (np);return -ENODEV ; }
Re: [PATCH 6/7] arch/powerpc/platforms/maple/setup.c: Add of_node_put to avoid memory leak
Quoted 50 lines · Julia Lawall
Add a call to
of_node_putin the error handling code following a call toof_find_node_by_path.The semantic match that finds this problem is as follows:
(http://coccinelle.lip6.fr/)// <smpl>
@r exists@
local idexpression x;
expression E,E1;
statement S;
@@*x =
(of_find_node_by_path|of_find_node_by_name |of_find_node_by_phandle |of_get_parent |of_get_next_parent |of_get_next_child |of_find_compatible_node |of_match_node)(...);
...
if (x = NULL) S
<... when != x = E
*if (...) {
... when !=of_node_put(x)when != if (...) { ... of_node_put(x); ... }(
return <+...x...+>;
|
* return ...;
)
}
...>of_node_put(x);
// </smpl>Signed-off-by Julia Lawall <[email protected]>--- arch/powerpc/platforms/maple/setup.c | 1 + 1 file changed, 1 insertion(+)arch/powerpc/platforms/maple/setup.c +0
-0
arch/powerpc/platforms/maple/setup.c static int __init maple_cpc925_edac_setup(void) · line 361
Quoted 4 lines
arch/powerpc/platforms/maple/setup.c +1
-0@@ -358,6 +358,7 @@ static int __init maple_cpc925_edac_setup(void) model = (const unsigned char *)of_get_property (np,"model" ,NULL );if (!model) {printk (KERN_ERR "%s: Unabel to get model info\n" , __func__); +of_node_put (np);
This patch should also fix the exact same problem after a call to of_find_node_by_type() in the same function (line 370).
Quoted 4 lines
arch/powerpc/platforms/maple/setup.c +0
-0return -ENODEV ; }
PATCH 7/7 arch/powerpc/platforms/cell: Add of_node_put to avoid memory leak
In reply to Julia LawallAdd calls to of_node_put in the error handling code following calls to of_find_node_by_path and of_find_node_by_phandle.
The semantic match that finds this problem is as follows:
(http://coccinelle.lip6.fr/)
// <smpl>
@r exists@
local idexpression x;
expression E,E1;
statement S;
@@
*x =
(of_find_node_by_path
|of_find_node_by_name |of_find_node_by_phandle |of_get_parent |of_get_next_parent |of_get_next_child |of_find_compatible_node |of_match_node
)(...);
...
if (x = NULL) S
<... when != x = E
*if (...) {
... when != of_node_put(x)
when != if (...) { ... of_node_put(x); ... }(
return <+...x...+>;
|
* return ...;
)
}
...>of_node_put(x);
// </smpl>
--- arch/powerpc/platforms/cell/ras.c | 4 +++- arch/powerpc/platforms/cell/spider-pic.c | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-)
arch/powerpc/platforms/cell/ras.c +3 -1
@@ -173,8 +173,10 @@ static int __init cbe_ptcal_enable(void)return -ENODEV ; size =of_get_property (np,"ibm,cbe-ptcal-size" ,NULL ); -if (!size) +if (!size) { +of_node_put (np);return -ENODEV ; + }pr_debug ("%s: enabling PTCAL, size = 0x%x\n" , __func__, *size); order =get_order (*size);
arch/powerpc/platforms/cell/spider-pic.c +3 -1
@@ -258,8 +258,10 @@ static unsigned int __init spider_find_cascade_and_node(struct spider_pic *pic)return NO_IRQ ; imap += intsize +1 ; tmp =of_get_property (iic,"#interrupt-cells" ,NULL ); -if (tmp =NULL ) +if (tmp =NULL ) { +of_node_put (iic);return NO_IRQ ; + } intsize = *tmp;/* Assume unit is last entry of interrupt specifier */ unit = imap[intsize -1 ];
Re: [PATCH 7/7] arch/powerpc/platforms/cell: Add of_node_put to avoid memory leak
Quoted 39 lines · Julia Lawall
Add calls to
of_node_putin the error handling code following calls toof_find_node_by_pathandof_find_node_by_phandle.The semantic match that finds this problem is as follows:
(http://coccinelle.lip6.fr/)// <smpl>
@r exists@
local idexpression x;
expression E,E1;
statement S;
@@*x =
(of_find_node_by_path|of_find_node_by_name |of_find_node_by_phandle |of_get_parent |of_get_next_parent |of_get_next_child |of_find_compatible_node |of_match_node)(...);
...
if (x = NULL) S
<... when != x = E
*if (...) {
... when !=of_node_put(x)when != if (...) { ... of_node_put(x); ... }(
return <+...x...+>;
|
* return ...;
)
}
...>of_node_put(x);
// </smpl>
Quoted 1 line
Signed-off-by Julia Lawall <[email protected]>
Quoted 39 lines
--- arch/powerpc/platforms/cell/ras.c | 4 +++- arch/powerpc/platforms/cell/spider-pic.c | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-)arch/powerpc/platforms/cell/ras.c +3
-1@@ -173,8 +173,10 @@ static int __init cbe_ptcal_enable(void)return -ENODEV ; size =of_get_property (np,"ibm,cbe-ptcal-size" ,NULL ); -if (!size) +if (!size) { +of_node_put (np);return -ENODEV ; + }pr_debug ("%s: enabling PTCAL, size = 0x%x\n" , __func__, *size); order =get_order (*size);arch/powerpc/platforms/cell/spider-pic.c +3
-1@@ -258,8 +258,10 @@ static unsigned int __init spider_find_cascade_and_node(struct spider_pic *pic)return NO_IRQ ; imap += intsize +1 ; tmp =of_get_property (iic,"#interrupt-cells" ,NULL ); -if (tmp =NULL ) +if (tmp =NULL ) { +of_node_put (iic);return NO_IRQ ; + } intsize = *tmp;/* Assume unit is last entry of interrupt specifier */ unit = imap[intsize -1 ];