lkml.org 
[lkml]   [2010]   [May]   [10]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    Date
    From
    SubjectRe: [PATCH] Check kmalloc return value before use the buffer
    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


    \
     
     \ /
      Last update: 2010-05-12 10:15    [W:0.041 / U:0.032 seconds]
    ©2003-2016 Jasper Spaans. hosted at Digital OceanAdvertise on this site