diff mbox series

i2c: busses: i2c-fsi.c: Add of_put_node() before break

Message ID 20190706131911.3068-1-nishkadg.linux@gmail.com
State Accepted
Headers show
Series i2c: busses: i2c-fsi.c: Add of_put_node() before break | expand

Commit Message

Nishka Dasgupta July 6, 2019, 1:19 p.m. UTC
Each iteration of for_each_available_childe_of_node puts the previous
node, but in the case of a break from the middle of the loop, there
is no put, thus causing a memory leak. Add an of_node_put before the
break.
Issue found with Coccinelle.

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

Comments

Wolfram Sang Sept. 3, 2019, 6:15 p.m. UTC | #1
On Sat, Jul 06, 2019 at 06:49:11PM +0530, Nishka Dasgupta wrote:
> Each iteration of for_each_available_childe_of_node puts the previous
> node, but in the case of a break from the middle of the loop, there
> is no put, thus causing a memory leak. Add an of_node_put before the
> break.
> Issue found with Coccinelle.
> 
> Signed-off-by: Nishka Dasgupta <nishkadg.linux@gmail.com>
> ---

Eddie, are you okay with this change?

>  drivers/i2c/busses/i2c-fsi.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/i2c/busses/i2c-fsi.c b/drivers/i2c/busses/i2c-fsi.c
> index 1e2be2219a60..5e01875082c3 100644
> --- a/drivers/i2c/busses/i2c-fsi.c
> +++ b/drivers/i2c/busses/i2c-fsi.c
> @@ -685,8 +685,10 @@ static int fsi_i2c_probe(struct device *dev)
>  			continue;
>  
>  		port = kzalloc(sizeof(*port), GFP_KERNEL);
> -		if (!port)
> +		if (!port) {
> +			of_node_put(np);
>  			break;
> +		}
>  
>  		port->master = i2c;
>  		port->port = port_no;
> -- 
> 2.19.1
>
Eddie James Sept. 3, 2019, 6:18 p.m. UTC | #2
On 9/3/19 1:15 PM, Wolfram Sang wrote:
> On Sat, Jul 06, 2019 at 06:49:11PM +0530, Nishka Dasgupta wrote:
>> Each iteration of for_each_available_childe_of_node puts the previous
>> node, but in the case of a break from the middle of the loop, there
>> is no put, thus causing a memory leak. Add an of_node_put before the
>> break.
>> Issue found with Coccinelle.
>>
>> Signed-off-by: Nishka Dasgupta <nishkadg.linux@gmail.com>
>> ---
> Eddie, are you okay with this change?


Yes, sorry must have missed this when it first came in.

Thanks.


Reviewed-by: Eddie James <eajames@linux.ibm.com>


>
>>   drivers/i2c/busses/i2c-fsi.c | 4 +++-
>>   1 file changed, 3 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/i2c/busses/i2c-fsi.c b/drivers/i2c/busses/i2c-fsi.c
>> index 1e2be2219a60..5e01875082c3 100644
>> --- a/drivers/i2c/busses/i2c-fsi.c
>> +++ b/drivers/i2c/busses/i2c-fsi.c
>> @@ -685,8 +685,10 @@ static int fsi_i2c_probe(struct device *dev)
>>   			continue;
>>   
>>   		port = kzalloc(sizeof(*port), GFP_KERNEL);
>> -		if (!port)
>> +		if (!port) {
>> +			of_node_put(np);
>>   			break;
>> +		}
>>   
>>   		port->master = i2c;
>>   		port->port = port_no;
>> -- 
>> 2.19.1
>>
Wolfram Sang Sept. 3, 2019, 6:33 p.m. UTC | #3
On Sat, Jul 06, 2019 at 06:49:11PM +0530, Nishka Dasgupta wrote:
> Each iteration of for_each_available_childe_of_node puts the previous
> node, but in the case of a break from the middle of the loop, there
> is no put, thus causing a memory leak. Add an of_node_put before the
> break.
> Issue found with Coccinelle.
> 
> Signed-off-by: Nishka Dasgupta <nishkadg.linux@gmail.com>

Applied to for-next, thanks!
diff mbox series

Patch

diff --git a/drivers/i2c/busses/i2c-fsi.c b/drivers/i2c/busses/i2c-fsi.c
index 1e2be2219a60..5e01875082c3 100644
--- a/drivers/i2c/busses/i2c-fsi.c
+++ b/drivers/i2c/busses/i2c-fsi.c
@@ -685,8 +685,10 @@  static int fsi_i2c_probe(struct device *dev)
 			continue;
 
 		port = kzalloc(sizeof(*port), GFP_KERNEL);
-		if (!port)
+		if (!port) {
+			of_node_put(np);
 			break;
+		}
 
 		port->master = i2c;
 		port->port = port_no;