[PATCH 07/11] soc: dove: add missing of_node_put

Julia Lawall posted 11 patches 1 year ago
[PATCH 07/11] soc: dove: add missing of_node_put
Posted by Julia Lawall 1 year ago
for_each_available_child_of_node performs an of_node_get
on each iteration, so a break out of the loop requires an
of_node_put.

This was done using the Coccinelle semantic patch
iterators/for_each_child.cocci

Signed-off-by: Julia Lawall <Julia.Lawall@inria.fr>

---
 drivers/soc/dove/pmu.c |    5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff -u -p a/drivers/soc/dove/pmu.c b/drivers/soc/dove/pmu.c
--- a/drivers/soc/dove/pmu.c
+++ b/drivers/soc/dove/pmu.c
@@ -410,13 +410,16 @@ int __init dove_init_pmu(void)
 		struct pmu_domain *domain;
 
 		domain = kzalloc(sizeof(*domain), GFP_KERNEL);
-		if (!domain)
+		if (!domain) {
+			of_node_put(np);
 			break;
+		}
 
 		domain->pmu = pmu;
 		domain->base.name = kasprintf(GFP_KERNEL, "%pOFn", np);
 		if (!domain->base.name) {
 			kfree(domain);
+			of_node_put(np);
 			break;
 		}
Re: [PATCH 07/11] soc: dove: add missing of_node_put
Posted by Gregory CLEMENT 1 year ago
Julia Lawall <Julia.Lawall@inria.fr> writes:

> for_each_available_child_of_node performs an of_node_get
> on each iteration, so a break out of the loop requires an
> of_node_put.
>
> This was done using the Coccinelle semantic patch
> iterators/for_each_child.cocci
>
> Signed-off-by: Julia Lawall <Julia.Lawall@inria.fr>

Applied on mvebu/arm

Thanks,

Gregory
>
> ---
>  drivers/soc/dove/pmu.c |    5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff -u -p a/drivers/soc/dove/pmu.c b/drivers/soc/dove/pmu.c
> --- a/drivers/soc/dove/pmu.c
> +++ b/drivers/soc/dove/pmu.c
> @@ -410,13 +410,16 @@ int __init dove_init_pmu(void)
>  		struct pmu_domain *domain;
>  
>  		domain = kzalloc(sizeof(*domain), GFP_KERNEL);
> -		if (!domain)
> +		if (!domain) {
> +			of_node_put(np);
>  			break;
> +		}
>  
>  		domain->pmu = pmu;
>  		domain->base.name = kasprintf(GFP_KERNEL, "%pOFn", np);
>  		if (!domain->base.name) {
>  			kfree(domain);
> +			of_node_put(np);
>  			break;
>  		}
>  
>

-- 
Gregory Clement, Bootlin
Embedded Linux and Kernel engineering
http://bootlin.com