soc: amlogic: meson-gx-socinfo: Add of_node_put() before return
diff mbox series

Message ID 20190819072706.31732-1-nishkadg.linux@gmail.com
State New
Headers show
Series
  • soc: amlogic: meson-gx-socinfo: Add of_node_put() before return
Related show

Commit Message

Nishka Dasgupta Aug. 19, 2019, 7:27 a.m. UTC
The variable np in function meson_gx_socinfo_init takes the return value
of of_find_compatible_node, which gets a node but does not put it. If
this node is not put it may cause a memory leak. Hence put np after its
usefulness has been exhausted.
Issue found with Coccinelle.

Signed-off-by: Nishka Dasgupta <nishkadg.linux@gmail.com>
---
 drivers/soc/amlogic/meson-gx-socinfo.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Neil Armstrong Aug. 19, 2019, 8:05 a.m. UTC | #1
On 19/08/2019 09:27, Nishka Dasgupta wrote:
> The variable np in function meson_gx_socinfo_init takes the return value
> of of_find_compatible_node, which gets a node but does not put it. If
> this node is not put it may cause a memory leak. Hence put np after its
> usefulness has been exhausted.
> Issue found with Coccinelle.
> 
> Signed-off-by: Nishka Dasgupta <nishkadg.linux@gmail.com>
> ---
>  drivers/soc/amlogic/meson-gx-socinfo.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/soc/amlogic/meson-gx-socinfo.c b/drivers/soc/amlogic/meson-gx-socinfo.c
> index bca34954518e..13695a72c695 100644
> --- a/drivers/soc/amlogic/meson-gx-socinfo.c
> +++ b/drivers/soc/amlogic/meson-gx-socinfo.c
> @@ -138,8 +138,10 @@ static int __init meson_gx_socinfo_init(void)
>  	}
>  
>  	/* check if chip-id is available */
> -	if (!of_property_read_bool(np, "amlogic,has-chip-id"))
> +	if (!of_property_read_bool(np, "amlogic,has-chip-id")) {
> +		of_node_put(np);
>  		return -ENODEV;
> +	}
>  
>  	/* node should be a syscon */
>  	regmap = syscon_node_to_regmap(np);
> 

Thanks !

Reviewed-by: Neil Armstrong <narmstrong@baylibre.com>

Would need :
Fixes: a9daaba2965e ("soc: Add Amlogic SoC Information driver")

Neil
Kevin Hilman Aug. 20, 2019, 9:55 p.m. UTC | #2
Neil Armstrong <narmstrong@baylibre.com> writes:

> On 19/08/2019 09:27, Nishka Dasgupta wrote:
>> The variable np in function meson_gx_socinfo_init takes the return value
>> of of_find_compatible_node, which gets a node but does not put it. If
>> this node is not put it may cause a memory leak. Hence put np after its
>> usefulness has been exhausted.
>> Issue found with Coccinelle.
>> 
>> Signed-off-by: Nishka Dasgupta <nishkadg.linux@gmail.com>
>> ---
>>  drivers/soc/amlogic/meson-gx-socinfo.c | 4 +++-
>>  1 file changed, 3 insertions(+), 1 deletion(-)
>> 
>> diff --git a/drivers/soc/amlogic/meson-gx-socinfo.c b/drivers/soc/amlogic/meson-gx-socinfo.c
>> index bca34954518e..13695a72c695 100644
>> --- a/drivers/soc/amlogic/meson-gx-socinfo.c
>> +++ b/drivers/soc/amlogic/meson-gx-socinfo.c
>> @@ -138,8 +138,10 @@ static int __init meson_gx_socinfo_init(void)
>>  	}
>>  
>>  	/* check if chip-id is available */
>> -	if (!of_property_read_bool(np, "amlogic,has-chip-id"))
>> +	if (!of_property_read_bool(np, "amlogic,has-chip-id")) {
>> +		of_node_put(np);
>>  		return -ENODEV;
>> +	}
>>  
>>  	/* node should be a syscon */
>>  	regmap = syscon_node_to_regmap(np);
>> 
>
> Thanks !
>
> Reviewed-by: Neil Armstrong <narmstrong@baylibre.com>
>
> Would need :
> Fixes: a9daaba2965e ("soc: Add Amlogic SoC Information driver")

Thanks.

Queued for v5.4 with Neil's tag and the Fixes tag.

Kevin

Patch
diff mbox series

diff --git a/drivers/soc/amlogic/meson-gx-socinfo.c b/drivers/soc/amlogic/meson-gx-socinfo.c
index bca34954518e..13695a72c695 100644
--- a/drivers/soc/amlogic/meson-gx-socinfo.c
+++ b/drivers/soc/amlogic/meson-gx-socinfo.c
@@ -138,8 +138,10 @@  static int __init meson_gx_socinfo_init(void)
 	}
 
 	/* check if chip-id is available */
-	if (!of_property_read_bool(np, "amlogic,has-chip-id"))
+	if (!of_property_read_bool(np, "amlogic,has-chip-id")) {
+		of_node_put(np);
 		return -ENODEV;
+	}
 
 	/* node should be a syscon */
 	regmap = syscon_node_to_regmap(np);