All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] powerpc/nvram: Fix a memory leak in err path
@ 2015-12-09 10:00 xinhui
  2015-12-09 15:21 ` Nathan Fontenot
  2016-09-20 13:07 ` Michael Ellerman
  0 siblings, 2 replies; 4+ messages in thread
From: xinhui @ 2015-12-09 10:00 UTC (permalink / raw)
  To: linuxppc-dev, linux-kernel
  Cc: Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman,
	Hari Bathini, Christophe Jaillet, Nathan Fontenot, Andrzej Hajda


If kmemdup fails, We need kfree *buff* first then return -ENOMEM.
Otherwise there is a memory leak.

Signed-off-by: Pan Xinhui <xinhui.pan@linux.vnet.ibm.com>
---
 arch/powerpc/kernel/nvram_64.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/powerpc/kernel/nvram_64.c b/arch/powerpc/kernel/nvram_64.c
index 32e2652..21a278b7 100644
--- a/arch/powerpc/kernel/nvram_64.c
+++ b/arch/powerpc/kernel/nvram_64.c
@@ -542,9 +542,9 @@ static ssize_t nvram_pstore_read(u64 *id, enum pstore_type_id *type,
 			time->tv_nsec = 0;
 		}
 		*buf = kmemdup(buff + hdr_size, length, GFP_KERNEL);
+		kfree(buff);
 		if (*buf == NULL)
 			return -ENOMEM;
-		kfree(buff);
 
 		if (err_type == ERR_TYPE_KERNEL_PANIC_GZ)
 			*compressed = true;
-- 
2.5.0


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

* Re: [PATCH] powerpc/nvram: Fix a memory leak in err path
  2015-12-09 10:00 [PATCH] powerpc/nvram: Fix a memory leak in err path xinhui
@ 2015-12-09 15:21 ` Nathan Fontenot
  2015-12-09 23:52   ` xinhui
  2016-09-20 13:07 ` Michael Ellerman
  1 sibling, 1 reply; 4+ messages in thread
From: Nathan Fontenot @ 2015-12-09 15:21 UTC (permalink / raw)
  To: xinhui, linuxppc-dev, linux-kernel
  Cc: Andrzej Hajda, Christophe Jaillet, Hari Bathini, Paul Mackerras

On 12/09/2015 04:00 AM, xinhui wrote:
> 
> If kmemdup fails, We need kfree *buff* first then return -ENOMEM.
> Otherwise there is a memory leak.
> 
> Signed-off-by: Pan Xinhui <xinhui.pan@linux.vnet.ibm.com>

Reviewed-by: Nathan Fontenot <nfont@linux.vnet.ibm.com>

> ---
>  arch/powerpc/kernel/nvram_64.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/arch/powerpc/kernel/nvram_64.c b/arch/powerpc/kernel/nvram_64.c
> index 32e2652..21a278b7 100644
> --- a/arch/powerpc/kernel/nvram_64.c
> +++ b/arch/powerpc/kernel/nvram_64.c
> @@ -542,9 +542,9 @@ static ssize_t nvram_pstore_read(u64 *id, enum pstore_type_id *type,
>  			time->tv_nsec = 0;
>  		}
>  		*buf = kmemdup(buff + hdr_size, length, GFP_KERNEL);
> +		kfree(buff);
>  		if (*buf == NULL)
>  			return -ENOMEM;
> -		kfree(buff);
>  
>  		if (err_type == ERR_TYPE_KERNEL_PANIC_GZ)
>  			*compressed = true;
> 


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

* Re: [PATCH] powerpc/nvram: Fix a memory leak in err path
  2015-12-09 15:21 ` Nathan Fontenot
@ 2015-12-09 23:52   ` xinhui
  0 siblings, 0 replies; 4+ messages in thread
From: xinhui @ 2015-12-09 23:52 UTC (permalink / raw)
  To: Nathan Fontenot, xinhui, linuxppc-dev, linux-kernel
  Cc: Andrzej Hajda, Christophe Jaillet, Hari Bathini, Paul Mackerras


On 2015/12/9 23:21, Nathan Fontenot wrote:
> On 12/09/2015 04:00 AM, xinhui wrote:
>>
>> If kmemdup fails, We need kfree *buff* first then return -ENOMEM.
>> Otherwise there is a memory leak.
>>
>> Signed-off-by: Pan Xinhui <xinhui.pan@linux.vnet.ibm.com>
>
> Reviewed-by: Nathan Fontenot <nfont@linux.vnet.ibm.com>
>

Hi Nathan,
	thank you for doing that :)

thanks
xinhui

>> ---
>>   arch/powerpc/kernel/nvram_64.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/arch/powerpc/kernel/nvram_64.c b/arch/powerpc/kernel/nvram_64.c
>> index 32e2652..21a278b7 100644
>> --- a/arch/powerpc/kernel/nvram_64.c
>> +++ b/arch/powerpc/kernel/nvram_64.c
>> @@ -542,9 +542,9 @@ static ssize_t nvram_pstore_read(u64 *id, enum pstore_type_id *type,
>>   			time->tv_nsec = 0;
>>   		}
>>   		*buf = kmemdup(buff + hdr_size, length, GFP_KERNEL);
>> +		kfree(buff);
>>   		if (*buf == NULL)
>>   			return -ENOMEM;
>> -		kfree(buff);
>>
>>   		if (err_type == ERR_TYPE_KERNEL_PANIC_GZ)
>>   			*compressed = true;
>>


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

* Re: powerpc/nvram: Fix a memory leak in err path
  2015-12-09 10:00 [PATCH] powerpc/nvram: Fix a memory leak in err path xinhui
  2015-12-09 15:21 ` Nathan Fontenot
@ 2016-09-20 13:07 ` Michael Ellerman
  1 sibling, 0 replies; 4+ messages in thread
From: Michael Ellerman @ 2016-09-20 13:07 UTC (permalink / raw)
  To: xinhui, linuxppc-dev, linux-kernel
  Cc: Andrzej Hajda, Christophe Jaillet, Nathan Fontenot, Hari Bathini,
	Paul Mackerras

On Wed, 2015-09-12 at 10:00:53 UTC, xinhui wrote:
> If kmemdup fails, We need kfree *buff* first then return -ENOMEM.
> Otherwise there is a memory leak.
> 
> Signed-off-by: Pan Xinhui <xinhui.pan@linux.vnet.ibm.com>
> Reviewed-by: Nathan Fontenot <nfont@linux.vnet.ibm.com>

Applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/0d0fecc5b5bfddb0e67bef985c

cheers

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

end of thread, other threads:[~2016-09-20 13:07 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-12-09 10:00 [PATCH] powerpc/nvram: Fix a memory leak in err path xinhui
2015-12-09 15:21 ` Nathan Fontenot
2015-12-09 23:52   ` xinhui
2016-09-20 13:07 ` Michael Ellerman

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.