public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Andy Isaacson <adi@hexapodia.org>
To: Steven Liu <lingjiujianke@gmail.com>,
	Nigel Cunningham <nigel@tuxonice.net>
Cc: Linus WALLEIJ <linus.walleij@stericsson.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] Check kmalloc return value before use the buffer
Date: Mon, 10 May 2010 14:49:46 -0700	[thread overview]
Message-ID: <20100510214946.GA4361@hexapodia.org> (raw)
In-Reply-To: <4BE4BDED.5050406@tuxonice.net> <z2mbd0d95d71005070017w7aa97001m2b81be6dbc1021b9@mail.gmail.com>

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

  parent reply	other threads:[~2010-05-10 21:49 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2010-05-10 22:08       ` Nigel Cunningham
  -- strict thread matches above, loose matches on Subject: below --
2010-05-07  9:05 Steven Liu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20100510214946.GA4361@hexapodia.org \
    --to=adi@hexapodia.org \
    --cc=lingjiujianke@gmail.com \
    --cc=linus.walleij@stericsson.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nigel@tuxonice.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox