All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] hwmon: ina3221.c: Add of_node_put() before return
@ 2019-07-06 13:21 Nishka Dasgupta
  2019-07-08 18:16 ` Guenter Roeck
  0 siblings, 1 reply; 3+ messages in thread
From: Nishka Dasgupta @ 2019-07-06 13:21 UTC (permalink / raw)
  To: jdelvare, linux, linux-hwmon; +Cc: Nishka Dasgupta

Each iteration of for_each_child_of_node puts the previous
node, but in the case of a return from the middle of the loop, there is
no put, thus causing a memory leak. Hence add an of_node_put before the
return.
Issue found with Coccinelle.

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

diff --git a/drivers/hwmon/ina3221.c b/drivers/hwmon/ina3221.c
index 55943b4dcc7b..0037e2bdacd6 100644
--- a/drivers/hwmon/ina3221.c
+++ b/drivers/hwmon/ina3221.c
@@ -713,8 +713,10 @@ static int ina3221_probe_from_dt(struct device *dev, struct ina3221_data *ina)
 
 	for_each_child_of_node(np, child) {
 		ret = ina3221_probe_child_from_dt(dev, child, ina);
-		if (ret)
+		if (ret) {
+			of_node_put(child);
 			return ret;
+		}
 	}
 
 	return 0;
-- 
2.19.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] hwmon: ina3221.c: Add of_node_put() before return
  2019-07-06 13:21 [PATCH] hwmon: ina3221.c: Add of_node_put() before return Nishka Dasgupta
@ 2019-07-08 18:16 ` Guenter Roeck
  2019-07-11  6:29   ` Nishka Dasgupta
  0 siblings, 1 reply; 3+ messages in thread
From: Guenter Roeck @ 2019-07-08 18:16 UTC (permalink / raw)
  To: Nishka Dasgupta; +Cc: jdelvare, linux-hwmon

On Sat, Jul 06, 2019 at 06:51:30PM +0530, Nishka Dasgupta wrote:
> Each iteration of for_each_child_of_node puts the previous
> node, but in the case of a return from the middle of the loop, there is
> no put, thus causing a memory leak. Hence add an of_node_put before the
> return.
> Issue found with Coccinelle.
> 
> Signed-off-by: Nishka Dasgupta <nishkadg.linux@gmail.com>

Applied. For future patches, please don't put source file extensions
into the subject line.

Thanks,
Guenter

> ---
>  drivers/hwmon/ina3221.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/hwmon/ina3221.c b/drivers/hwmon/ina3221.c
> index 55943b4dcc7b..0037e2bdacd6 100644
> --- a/drivers/hwmon/ina3221.c
> +++ b/drivers/hwmon/ina3221.c
> @@ -713,8 +713,10 @@ static int ina3221_probe_from_dt(struct device *dev, struct ina3221_data *ina)
>  
>  	for_each_child_of_node(np, child) {
>  		ret = ina3221_probe_child_from_dt(dev, child, ina);
> -		if (ret)
> +		if (ret) {
> +			of_node_put(child);
>  			return ret;
> +		}
>  	}
>  
>  	return 0;

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] hwmon: ina3221.c: Add of_node_put() before return
  2019-07-08 18:16 ` Guenter Roeck
@ 2019-07-11  6:29   ` Nishka Dasgupta
  0 siblings, 0 replies; 3+ messages in thread
From: Nishka Dasgupta @ 2019-07-11  6:29 UTC (permalink / raw)
  To: Guenter Roeck; +Cc: jdelvare, linux-hwmon

On 08/07/19 11:46 PM, Guenter Roeck wrote:
> On Sat, Jul 06, 2019 at 06:51:30PM +0530, Nishka Dasgupta wrote:
>> Each iteration of for_each_child_of_node puts the previous
>> node, but in the case of a return from the middle of the loop, there is
>> no put, thus causing a memory leak. Hence add an of_node_put before the
>> return.
>> Issue found with Coccinelle.
>>
>> Signed-off-by: Nishka Dasgupta <nishkadg.linux@gmail.com>
> 
> Applied. For future patches, please don't put source file extensions
> into the subject line.

I will keep that in mind, thank you.

Thanking you,
Nishka

> Thanks,
> Guenter
> 
>> ---
>>   drivers/hwmon/ina3221.c | 4 +++-
>>   1 file changed, 3 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/hwmon/ina3221.c b/drivers/hwmon/ina3221.c
>> index 55943b4dcc7b..0037e2bdacd6 100644
>> --- a/drivers/hwmon/ina3221.c
>> +++ b/drivers/hwmon/ina3221.c
>> @@ -713,8 +713,10 @@ static int ina3221_probe_from_dt(struct device *dev, struct ina3221_data *ina)
>>   
>>   	for_each_child_of_node(np, child) {
>>   		ret = ina3221_probe_child_from_dt(dev, child, ina);
>> -		if (ret)
>> +		if (ret) {
>> +			of_node_put(child);
>>   			return ret;
>> +		}
>>   	}
>>   
>>   	return 0;


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-07-11  6:29 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-06 13:21 [PATCH] hwmon: ina3221.c: Add of_node_put() before return Nishka Dasgupta
2019-07-08 18:16 ` Guenter Roeck
2019-07-11  6:29   ` Nishka Dasgupta

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.