public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Check kmalloc return value before use the buffer
@ 2010-05-07  2:41 Steven Liu
  2010-05-07  6:52 ` Linus WALLEIJ
  0 siblings, 1 reply; 17+ messages in thread
From: Steven Liu @ 2010-05-07  2:41 UTC (permalink / raw)
  To: linus.walleij; +Cc: linux-kernel

Hi,linus.walleij

          Check kmalloc return value before use the buffer


Signed-off-by: LiuQi <lingjiujianke@gmail.com>
---
 arch/arm/mach-u300/dummyspichip.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/arch/arm/mach-u300/dummyspichip.c
b/arch/arm/mach-u300/dummyspichip.c
index 962f9de..4f2af7c 100644
--- a/arch/arm/mach-u300/dummyspichip.c
+++ b/arch/arm/mach-u300/dummyspichip.c
@@ -63,6 +63,11 @@ static ssize_t dummy_looptest(struct device *dev,
 		goto out;
 	}
 	bigrxbuf_virtual = kmalloc(DMA_TEST_SIZE, GFP_KERNEL);
+	if (bigtxbuf_virtual == NULL) {
+		status = -ENOMEM;
+		kfree(bigtxbuf_virtual);
+		goto out;
+	}

 	/* Fill TXBUF with some happy pattern */
 	memset(bigtxbuf_virtual, 0xAA, DMA_TEST_SIZE);
-- 
1.6.0.3

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

* RE: [PATCH] Check kmalloc return value before use the buffer
  2010-05-07  2:41 [PATCH] Check kmalloc return value before use the buffer Steven Liu
@ 2010-05-07  6:52 ` Linus WALLEIJ
  2010-05-07  7:16   ` Steven Liu
  2010-05-07  7:17   ` Steven Liu
  0 siblings, 2 replies; 17+ messages in thread
From: Linus WALLEIJ @ 2010-05-07  6:52 UTC (permalink / raw)
  To: Steven Liu; +Cc: linux-kernel@vger.kernel.org

Hi Liu,

> Hi,linus.walleij
> 
>           Check kmalloc return value before use the buffer
> 
> 
> Signed-off-by: LiuQi <lingjiujianke@gmail.com>
> ---
>  arch/arm/mach-u300/dummyspichip.c |    5 +++++
>  1 files changed, 5 insertions(+), 0 deletions(-)
> 
> diff --git a/arch/arm/mach-u300/dummyspichip.c
> b/arch/arm/mach-u300/dummyspichip.c
> index 962f9de..4f2af7c 100644
> --- a/arch/arm/mach-u300/dummyspichip.c
> +++ b/arch/arm/mach-u300/dummyspichip.c
> @@ -63,6 +63,11 @@ static ssize_t dummy_looptest(struct device *dev,
>  		goto out;
>  	}
>  	bigrxbuf_virtual = kmalloc(DMA_TEST_SIZE, GFP_KERNEL);
> +	if (bigtxbuf_virtual == NULL) {
> +		status = -ENOMEM;
> +		kfree(bigtxbuf_virtual);

kfree():ing NULL is OK, but you just checked it to be NULL so why?

> +		goto out;
> +	}
> 
>  	/* Fill TXBUF with some happy pattern */
>  	memset(bigtxbuf_virtual, 0xAA, DMA_TEST_SIZE);

Otherwise the bug it fixes is good to fix.

Yours,
Linus Walleij

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

* Re: [PATCH] Check kmalloc return value before use the buffer
  2010-05-07  6:52 ` Linus WALLEIJ
@ 2010-05-07  7:16   ` Steven Liu
  2010-05-07  7:17   ` Steven Liu
  1 sibling, 0 replies; 17+ messages in thread
From: Steven Liu @ 2010-05-07  7:16 UTC (permalink / raw)
  To: Linus WALLEIJ; +Cc: linux-kernel@vger.kernel.org

Oh,I think I have a mistake


Signed-off-by: root <root@T-bagwell.(none)>
---
 arch/arm/mach-u300/dummyspichip.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/arch/arm/mach-u300/dummyspichip.c
b/arch/arm/mach-u300/dummyspichip.c
index 5f55012..df19f9b 100644
--- a/arch/arm/mach-u300/dummyspichip.c
+++ b/arch/arm/mach-u300/dummyspichip.c
@@ -64,6 +64,11 @@ static ssize_t dummy_looptest(struct device *dev,
 		goto out;
 	}
 	bigrxbuf_virtual = kmalloc(DMA_TEST_SIZE, GFP_KERNEL);
+	if (bigrxbuf_virtual == NULL) {
+		status = -ENOMEM;
+		kfree(bigtxbuf_virtual);
+		goto out;
+	}

 	/* Fill TXBUF with some happy pattern */
 	memset(bigtxbuf_virtual, 0xAA, DMA_TEST_SIZE);
-- 
1.6.0.3





what a bout this one, please?


Best regards!



2010/5/7 Linus WALLEIJ <linus.walleij@stericsson.com>:
> Hi Liu,
>
>> Hi,linus.walleij
>>
>>           Check kmalloc return value before use the buffer
>>
>>
>> Signed-off-by: LiuQi <lingjiujianke@gmail.com>
>> ---
>>  arch/arm/mach-u300/dummyspichip.c |    5 +++++
>>  1 files changed, 5 insertions(+), 0 deletions(-)
>>
>> diff --git a/arch/arm/mach-u300/dummyspichip.c
>> b/arch/arm/mach-u300/dummyspichip.c
>> index 962f9de..4f2af7c 100644
>> --- a/arch/arm/mach-u300/dummyspichip.c
>> +++ b/arch/arm/mach-u300/dummyspichip.c
>> @@ -63,6 +63,11 @@ static ssize_t dummy_looptest(struct device *dev,
>>               goto out;
>>       }
>>       bigrxbuf_virtual = kmalloc(DMA_TEST_SIZE, GFP_KERNEL);
>> +     if (bigtxbuf_virtual == NULL) {
>> +             status = -ENOMEM;
>> +             kfree(bigtxbuf_virtual);
>
> kfree():ing NULL is OK, but you just checked it to be NULL so why?
>
>> +             goto out;
>> +     }
>>
>>       /* Fill TXBUF with some happy pattern */
>>       memset(bigtxbuf_virtual, 0xAA, DMA_TEST_SIZE);
>
> Otherwise the bug it fixes is good to fix.
>
> Yours,
> Linus Walleij
>

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

* Re: [PATCH] Check kmalloc return value before use the buffer
  2010-05-07  6:52 ` Linus WALLEIJ
  2010-05-07  7:16   ` Steven Liu
@ 2010-05-07  7:17   ` Steven Liu
  2010-05-07  9:37     ` Nigel Cunningham
                       ` (2 more replies)
  1 sibling, 3 replies; 17+ messages in thread
From: Steven Liu @ 2010-05-07  7:17 UTC (permalink / raw)
  To: Linus WALLEIJ; +Cc: linux-kernel@vger.kernel.org

Signed-off-by: LiuQi <lingjiujianke@gmail.com>
---
 arch/arm/mach-u300/dummyspichip.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/arch/arm/mach-u300/dummyspichip.c
b/arch/arm/mach-u300/dummyspichip.c
index 5f55012..df19f9b 100644
--- a/arch/arm/mach-u300/dummyspichip.c
+++ b/arch/arm/mach-u300/dummyspichip.c
@@ -64,6 +64,11 @@ static ssize_t dummy_looptest(struct device *dev,
 		goto out;
 	}
 	bigrxbuf_virtual = kmalloc(DMA_TEST_SIZE, GFP_KERNEL);
+	if (bigrxbuf_virtual == NULL) {
+		status = -ENOMEM;
+		kfree(bigtxbuf_virtual);
+		goto out;
+	}

 	/* Fill TXBUF with some happy pattern */
 	memset(bigtxbuf_virtual, 0xAA, DMA_TEST_SIZE);
-- 
1.6.0.3

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

* [PATCH] Check kmalloc return value before use the buffer
@ 2010-05-07  9:05 Steven Liu
  0 siblings, 0 replies; 17+ messages in thread
From: Steven Liu @ 2010-05-07  9:05 UTC (permalink / raw)
  To: Linus WALLEIJ, linux-kernel

Signed-off-by: LiuQi <lingjiujianke@gmail.com>
---
 arch/arm/mach-u300/dummyspichip.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/arch/arm/mach-u300/dummyspichip.c
b/arch/arm/mach-u300/dummyspichip.c
index 5f55012..df19f9b 100644
--- a/arch/arm/mach-u300/dummyspichip.c
+++ b/arch/arm/mach-u300/dummyspichip.c
@@ -64,6 +64,11 @@ static ssize_t dummy_looptest(struct device *dev,
 		goto out;
 	}
 	bigrxbuf_virtual = kmalloc(DMA_TEST_SIZE, GFP_KERNEL);
+	if (bigrxbuf_virtual == NULL) {
+		status = -ENOMEM;
+		kfree(bigtxbuf_virtual);
+		goto out;
+	}

 	/* Fill TXBUF with some happy pattern */
 	memset(bigtxbuf_virtual, 0xAA, DMA_TEST_SIZE);
-- 
1.6.0.3

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

* Re: [PATCH] Check kmalloc return value before use the buffer
  2010-05-07  7:17   ` Steven Liu
@ 2010-05-07  9:37     ` Nigel Cunningham
  2010-05-07  9:37     ` Nigel Cunningham
  2010-05-10 21:49     ` Andy Isaacson
  2 siblings, 0 replies; 17+ messages in thread
From: Nigel Cunningham @ 2010-05-07  9:37 UTC (permalink / raw)
  To: Steven Liu; +Cc: Linus WALLEIJ, linux-kernel@vger.kernel.org

Hi.

No commit comment?

On 07/05/10 17:17, Steven Liu wrote:
> Signed-off-by: LiuQi<lingjiujianke@gmail.com>
> ---
>   arch/arm/mach-u300/dummyspichip.c |    5 +++++
>   1 files changed, 5 insertions(+), 0 deletions(-)
>
> diff --git a/arch/arm/mach-u300/dummyspichip.c
> b/arch/arm/mach-u300/dummyspichip.c
> index 5f55012..df19f9b 100644
> --- a/arch/arm/mach-u300/dummyspichip.c
> +++ b/arch/arm/mach-u300/dummyspichip.c
> @@ -64,6 +64,11 @@ static ssize_t dummy_looptest(struct device *dev,
>   		goto out;
>   	}
>   	bigrxbuf_virtual = kmalloc(DMA_TEST_SIZE, GFP_KERNEL);
> +	if (bigrxbuf_virtual == NULL) {
> +		status = -ENOMEM;
> +		kfree(bigtxbuf_virtual);

Why kfree something you know is NULL?

Regards,

Nigel

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

* Re: [PATCH] Check kmalloc return value before use the buffer
  2010-05-07  7:17   ` Steven Liu
  2010-05-07  9:37     ` Nigel Cunningham
@ 2010-05-07  9:37     ` Nigel Cunningham
  2010-05-07  9:47       ` Steven Liu
  2010-05-07  9:50       ` Steven Liu
  2010-05-10 21:49     ` Andy Isaacson
  2 siblings, 2 replies; 17+ messages in thread
From: Nigel Cunningham @ 2010-05-07  9:37 UTC (permalink / raw)
  To: Steven Liu; +Cc: Linus WALLEIJ, linux-kernel@vger.kernel.org

Hi.

No commit comment?

On 07/05/10 17:17, Steven Liu wrote:
> Signed-off-by: LiuQi<lingjiujianke@gmail.com>
> ---
>   arch/arm/mach-u300/dummyspichip.c |    5 +++++
>   1 files changed, 5 insertions(+), 0 deletions(-)
>
> diff --git a/arch/arm/mach-u300/dummyspichip.c
> b/arch/arm/mach-u300/dummyspichip.c
> index 5f55012..df19f9b 100644
> --- a/arch/arm/mach-u300/dummyspichip.c
> +++ b/arch/arm/mach-u300/dummyspichip.c
> @@ -64,6 +64,11 @@ static ssize_t dummy_looptest(struct device *dev,
>   		goto out;
>   	}
>   	bigrxbuf_virtual = kmalloc(DMA_TEST_SIZE, GFP_KERNEL);
> +	if (bigrxbuf_virtual == NULL) {
> +		status = -ENOMEM;
> +		kfree(bigtxbuf_virtual);

Why kfree something you know is NULL?

Regards,

Nigel

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

* Re: [PATCH] Check kmalloc return value before use the buffer
  2010-05-07  9:37     ` Nigel Cunningham
@ 2010-05-07  9:47       ` Steven Liu
  2010-05-07  9:51         ` Nigel Cunningham
  2010-05-07 18:57         ` Linus WALLEIJ
  2010-05-07  9:50       ` Steven Liu
  1 sibling, 2 replies; 17+ messages in thread
From: Steven Liu @ 2010-05-07  9:47 UTC (permalink / raw)
  To: nigel; +Cc: Linus WALLEIJ, linux-kernel@vger.kernel.org

Hi, guy,

the code in arch/arm/mach-u300/dummyspichip.c is

    bigtxbuf_virtual = kmalloc(DMA_TEST_SIZE, GFP_KERNEL);
    if (bigtxbuf_virtual == NULL) {
        status = -ENOMEM;
        goto out;
    }
    bigrxbuf_virtual = kmalloc(DMA_TEST_SIZE, GFP_KERNEL);


if kmalloc memory space for bigrxbuf_virtual is NULL, when it have
kmalloc DMA_TEST_SIZE memory space for bigtxbuf_virtual,so ,if kmalloc
memory for bigtxbuf_virtual success and kmalloc memory for
bigrxbuf_virtual faild,i think we must kfree  bigtxbuf_virtual memory



best regards,



LiuQi
2010/5/7 Nigel Cunningham <nigel@tuxonice.net>:
> Hi.
>
> No commit comment?
>
> On 07/05/10 17:17, Steven Liu wrote:
>>
>> Signed-off-by: LiuQi<lingjiujianke@gmail.com>
>> ---
>>  arch/arm/mach-u300/dummyspichip.c |    5 +++++
>>  1 files changed, 5 insertions(+), 0 deletions(-)
>>
>> diff --git a/arch/arm/mach-u300/dummyspichip.c
>> b/arch/arm/mach-u300/dummyspichip.c
>> index 5f55012..df19f9b 100644
>> --- a/arch/arm/mach-u300/dummyspichip.c
>> +++ b/arch/arm/mach-u300/dummyspichip.c
>> @@ -64,6 +64,11 @@ static ssize_t dummy_looptest(struct device *dev,
>>                goto out;
>>        }
>>        bigrxbuf_virtual = kmalloc(DMA_TEST_SIZE, GFP_KERNEL);
>> +       if (bigrxbuf_virtual == NULL) {
>> +               status = -ENOMEM;
>> +               kfree(bigtxbuf_virtual);
>
> Why kfree something you know is NULL?
>
> Regards,
>
> Nigel
>

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

* Re: [PATCH] Check kmalloc return value before use the buffer
  2010-05-07  9:37     ` Nigel Cunningham
  2010-05-07  9:47       ` Steven Liu
@ 2010-05-07  9:50       ` Steven Liu
  2010-05-07  9:52         ` Nigel Cunningham
  1 sibling, 1 reply; 17+ messages in thread
From: Steven Liu @ 2010-05-07  9:50 UTC (permalink / raw)
  To: nigel; +Cc: Linus WALLEIJ, linux-kernel@vger.kernel.org

Check kmalloc return value before use the bigrxbuf_virtual ,when
bigrxbuf_virtual is NULL, kfree  bigtxbuf_virtual

2010/5/7 Nigel Cunningham <nigel@tuxonice.net>:
> Hi.
>
> No commit comment?
>
> On 07/05/10 17:17, Steven Liu wrote:
>>
>> Signed-off-by: LiuQi<lingjiujianke@gmail.com>
>> ---
>>  arch/arm/mach-u300/dummyspichip.c |    5 +++++
>>  1 files changed, 5 insertions(+), 0 deletions(-)
>>
>> diff --git a/arch/arm/mach-u300/dummyspichip.c
>> b/arch/arm/mach-u300/dummyspichip.c
>> index 5f55012..df19f9b 100644
>> --- a/arch/arm/mach-u300/dummyspichip.c
>> +++ b/arch/arm/mach-u300/dummyspichip.c
>> @@ -64,6 +64,11 @@ static ssize_t dummy_looptest(struct device *dev,
>>                goto out;
>>        }
>>        bigrxbuf_virtual = kmalloc(DMA_TEST_SIZE, GFP_KERNEL);
>> +       if (bigrxbuf_virtual == NULL) {
>> +               status = -ENOMEM;
>> +               kfree(bigtxbuf_virtual);
>
> Why kfree something you know is NULL?
>
> Regards,
>
> Nigel
>

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

* Re: [PATCH] Check kmalloc return value before use the buffer
  2010-05-07  9:47       ` Steven Liu
@ 2010-05-07  9:51         ` Nigel Cunningham
  2010-05-07 18:57         ` Linus WALLEIJ
  1 sibling, 0 replies; 17+ messages in thread
From: Nigel Cunningham @ 2010-05-07  9:51 UTC (permalink / raw)
  To: Steven Liu; +Cc: Linus WALLEIJ, linux-kernel@vger.kernel.org

Hi.

On 07/05/10 19:47, Steven Liu wrote:
> Hi, guy,
>
> the code in arch/arm/mach-u300/dummyspichip.c is
>
>      bigtxbuf_virtual = kmalloc(DMA_TEST_SIZE, GFP_KERNEL);
>      if (bigtxbuf_virtual == NULL) {
>          status = -ENOMEM;
>          goto out;
>      }
>      bigrxbuf_virtual = kmalloc(DMA_TEST_SIZE, GFP_KERNEL);
>
>
> if kmalloc memory space for bigrxbuf_virtual is NULL, when it have
> kmalloc DMA_TEST_SIZE memory space for bigtxbuf_virtual,so ,if kmalloc
> memory for bigtxbuf_virtual success and kmalloc memory for
> bigrxbuf_virtual faild,i think we must kfree  bigtxbuf_virtual memory

Ah, I see. I misread. Humble apologies :)

The other point still applies: You need to add a commit comment - even a 
simple one.

Regards,

Nigel

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

* Re: [PATCH] Check kmalloc return value before use the buffer
  2010-05-07  9:50       ` Steven Liu
@ 2010-05-07  9:52         ` Nigel Cunningham
  2010-05-07  9:55           ` Steven Liu
  0 siblings, 1 reply; 17+ messages in thread
From: Nigel Cunningham @ 2010-05-07  9:52 UTC (permalink / raw)
  To: Steven Liu; +Cc: Linus WALLEIJ, linux-kernel@vger.kernel.org

Hi.

On 07/05/10 19:50, Steven Liu wrote:
> Check kmalloc return value before use the bigrxbuf_virtual ,when
> bigrxbuf_virtual is NULL, kfree  bigtxbuf_virtual

Ta :)

Nigel

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

* Re: [PATCH] Check kmalloc return value before use the buffer
  2010-05-07  9:52         ` Nigel Cunningham
@ 2010-05-07  9:55           ` Steven Liu
  0 siblings, 0 replies; 17+ messages in thread
From: Steven Liu @ 2010-05-07  9:55 UTC (permalink / raw)
  To: Nigel Cunningham; +Cc: Linus WALLEIJ, linux-kernel@vger.kernel.org

Hi, guy,

         Thanks for your help, :)


Best Regards


LiuQi

2010/5/7 Nigel Cunningham <nigel@tuxonice.net>:
> Hi.
>
> On 07/05/10 19:50, Steven Liu wrote:
>>
>> Check kmalloc return value before use the bigrxbuf_virtual ,when
>> bigrxbuf_virtual is NULL, kfree  bigtxbuf_virtual
>
> Ta :)
>
> Nigel
>

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

* RE: [PATCH] Check kmalloc return value before use the buffer
  2010-05-07  9:47       ` Steven Liu
  2010-05-07  9:51         ` Nigel Cunningham
@ 2010-05-07 18:57         ` Linus WALLEIJ
  2010-05-08  1:27           ` Nigel Cunningham
  1 sibling, 1 reply; 17+ messages in thread
From: Linus WALLEIJ @ 2010-05-07 18:57 UTC (permalink / raw)
  To: Steven Liu, nigel@tuxonice.net; +Cc: linux-kernel@vger.kernel.org

[Steven]

> the code in arch/arm/mach-u300/dummyspichip.c is
> 
>     bigtxbuf_virtual = kmalloc(DMA_TEST_SIZE, GFP_KERNEL);
>     if (bigtxbuf_virtual == NULL) {
>         status = -ENOMEM;
>         goto out;
>     }
>     bigrxbuf_virtual = kmalloc(DMA_TEST_SIZE, GFP_KERNEL);
> 
> 
> if kmalloc memory space for bigrxbuf_virtual is NULL, when it have
> kmalloc DMA_TEST_SIZE memory space for bigtxbuf_virtual,so ,if kmalloc
> memory for bigtxbuf_virtual success and kmalloc memory for
> bigrxbuf_virtual faild,i think we must kfree  bigtxbuf_virtual memory

Ha, I also misread tx for rx, sorry.

Acked-by: Linus Walleij <linus.walleij@stericsson.com>

Yours,
Linus Walleij

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

* Re: [PATCH] Check kmalloc return value before use the buffer
  2010-05-07 18:57         ` Linus WALLEIJ
@ 2010-05-08  1:27           ` Nigel Cunningham
  2010-05-08  8:56             ` Steven Liu
  0 siblings, 1 reply; 17+ messages in thread
From: Nigel Cunningham @ 2010-05-08  1:27 UTC (permalink / raw)
  To: Linus WALLEIJ; +Cc: Steven Liu, linux-kernel@vger.kernel.org

Hi again.

On 08/05/10 04:57, Linus WALLEIJ wrote:
> [Steven]
>
>> the code in arch/arm/mach-u300/dummyspichip.c is
>>
>>      bigtxbuf_virtual = kmalloc(DMA_TEST_SIZE, GFP_KERNEL);
>>      if (bigtxbuf_virtual == NULL) {
>>          status = -ENOMEM;
>>          goto out;
>>      }
>>      bigrxbuf_virtual = kmalloc(DMA_TEST_SIZE, GFP_KERNEL);
>>
>>
>> if kmalloc memory space for bigrxbuf_virtual is NULL, when it have
>> kmalloc DMA_TEST_SIZE memory space for bigtxbuf_virtual,so ,if kmalloc
>> memory for bigtxbuf_virtual success and kmalloc memory for
>> bigrxbuf_virtual faild,i think we must kfree  bigtxbuf_virtual memory
>
> Ha, I also misread tx for rx, sorry.

I've just looked again, and the original version did have rx in the 
test. We weren't seeing things :)

> Acked-by: Linus Walleij<linus.walleij@stericsson.com>

Acked-by: Nigel Cunningham <nigel@tuxonice.net>

Regards,

Nigel

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

* Re: [PATCH] Check kmalloc return value before use the buffer
  2010-05-08  1:27           ` Nigel Cunningham
@ 2010-05-08  8:56             ` Steven Liu
  0 siblings, 0 replies; 17+ messages in thread
From: Steven Liu @ 2010-05-08  8:56 UTC (permalink / raw)
  To: Nigel Cunningham; +Cc: Linus WALLEIJ, linux-kernel@vger.kernel.org

[Linus WALLEIJ]

   can this patch fix in?

2010/5/8 Nigel Cunningham <nigel@tuxonice.net>:
> Hi again.
>
> On 08/05/10 04:57, Linus WALLEIJ wrote:
>>
>> [Steven]
>>
>>> the code in arch/arm/mach-u300/dummyspichip.c is
>>>
>>>     bigtxbuf_virtual = kmalloc(DMA_TEST_SIZE, GFP_KERNEL);
>>>     if (bigtxbuf_virtual == NULL) {
>>>         status = -ENOMEM;
>>>         goto out;
>>>     }
>>>     bigrxbuf_virtual = kmalloc(DMA_TEST_SIZE, GFP_KERNEL);
>>>
>>>
>>> if kmalloc memory space for bigrxbuf_virtual is NULL, when it have
>>> kmalloc DMA_TEST_SIZE memory space for bigtxbuf_virtual,so ,if kmalloc
>>> memory for bigtxbuf_virtual success and kmalloc memory for
>>> bigrxbuf_virtual faild,i think we must kfree  bigtxbuf_virtual memory
>>
>> Ha, I also misread tx for rx, sorry.
>
> I've just looked again, and the original version did have rx in the test. We
> weren't seeing things :)
>
>> Acked-by: Linus Walleij<linus.walleij@stericsson.com>
>
> Acked-by: Nigel Cunningham <nigel@tuxonice.net>
>
> Regards,
>
> Nigel
>

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

* Re: [PATCH] Check kmalloc return value before use the buffer
  2010-05-07  7:17   ` Steven Liu
  2010-05-07  9:37     ` Nigel Cunningham
  2010-05-07  9:37     ` Nigel Cunningham
@ 2010-05-10 21:49     ` Andy Isaacson
  2010-05-10 22:08       ` Nigel Cunningham
  2 siblings, 1 reply; 17+ messages in thread
From: Andy Isaacson @ 2010-05-10 21:49 UTC (permalink / raw)
  To: Steven Liu, Nigel Cunningham; +Cc: Linus WALLEIJ, linux-kernel@vger.kernel.org

On Fri, May 07, 2010 at 03:17:39PM +0800, Steven Liu wrote:
>  	bigrxbuf_virtual = kmalloc(DMA_TEST_SIZE, GFP_KERNEL);
> +	if (bigrxbuf_virtual == NULL) {
> +		status = -ENOMEM;
> +		kfree(bigtxbuf_virtual);
> +		goto out;
> +	}

On Sat, May 08, 2010 at 11:27:09AM +1000, Nigel Cunningham wrote:
>> Acked-by: Linus Walleij<linus.walleij@stericsson.com>
>
> Acked-by: Nigel Cunningham <nigel@tuxonice.net>

NACK.  Don't duplicate kfree(), instead do something like

--- a/arch/arm/mach-u300/dummyspichip.c
+++ b/arch/arm/mach-u300/dummyspichip.c
@@ -58,12 +58,13 @@ static ssize_t dummy_looptest(struct device *dev,
        if (mutex_lock_interruptible(&p_dummy->lock))
                return -ERESTARTSYS;
 
+       status = -ENOMEM;
        bigtxbuf_virtual = kmalloc(DMA_TEST_SIZE, GFP_KERNEL);
-       if (bigtxbuf_virtual == NULL) {
-               status = -ENOMEM;
+       if (bigtxbuf_virtual == NULL)
                goto out;
-       }
        bigrxbuf_virtual = kmalloc(DMA_TEST_SIZE, GFP_KERNEL);
+       if (bigrxbuf_virtual == NULL)
+               goto out_free_tx;
 
        /* Fill TXBUF with some happy pattern */
        memset(bigtxbuf_virtual, 0xAA, DMA_TEST_SIZE);
@@ -215,6 +216,7 @@ static ssize_t dummy_looptest(struct device *dev,
 
        status = sprintf(buf, "loop test complete\n");
        kfree(bigrxbuf_virtual);
+ out_free_tx:
        kfree(bigtxbuf_virtual);
  out:
        mutex_unlock(&p_dummy->lock);

-andy

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

* Re: [PATCH] Check kmalloc return value before use the buffer
  2010-05-10 21:49     ` Andy Isaacson
@ 2010-05-10 22:08       ` Nigel Cunningham
  0 siblings, 0 replies; 17+ messages in thread
From: Nigel Cunningham @ 2010-05-10 22:08 UTC (permalink / raw)
  To: Andy Isaacson; +Cc: Steven Liu, Linus WALLEIJ, linux-kernel@vger.kernel.org

Hi.

On 11/05/10 07:49, Andy Isaacson wrote:
> On Fri, May 07, 2010 at 03:17:39PM +0800, Steven Liu wrote:
>>   	bigrxbuf_virtual = kmalloc(DMA_TEST_SIZE, GFP_KERNEL);
>> +	if (bigrxbuf_virtual == NULL) {
>> +		status = -ENOMEM;
>> +		kfree(bigtxbuf_virtual);
>> +		goto out;
>> +	}
>
> On Sat, May 08, 2010 at 11:27:09AM +1000, Nigel Cunningham wrote:
>>> Acked-by: Linus Walleij<linus.walleij@stericsson.com>
>>
>> Acked-by: Nigel Cunningham<nigel@tuxonice.net>
>
> NACK.  Don't duplicate kfree(), instead do something like

Yeah... that is a better way of doing it.

Regards,

Nigel

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

end of thread, other threads:[~2010-05-10 22:08 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-05-07  2:41 [PATCH] Check kmalloc return value before use the buffer Steven Liu
2010-05-07  6:52 ` Linus WALLEIJ
2010-05-07  7:16   ` Steven Liu
2010-05-07  7:17   ` Steven Liu
2010-05-07  9:37     ` Nigel Cunningham
2010-05-07  9:37     ` Nigel Cunningham
2010-05-07  9:47       ` Steven Liu
2010-05-07  9:51         ` Nigel Cunningham
2010-05-07 18:57         ` Linus WALLEIJ
2010-05-08  1:27           ` Nigel Cunningham
2010-05-08  8:56             ` Steven Liu
2010-05-07  9:50       ` Steven Liu
2010-05-07  9:52         ` Nigel Cunningham
2010-05-07  9:55           ` Steven Liu
2010-05-10 21:49     ` Andy Isaacson
2010-05-10 22:08       ` Nigel Cunningham
  -- strict thread matches above, loose matches on Subject: below --
2010-05-07  9:05 Steven Liu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox