lkml.org 
[lkml]   [2000]   [Aug]   [21]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    Date
    From
    Subject[PATCH] drivers/scsi/3w-xxxx.c: fix leak on failure
    Hi,

    Please take a look and consider applying.

    - Arnaldo

    --- linux-2.4.0-test7-pre5/drivers/scsi/3w-xxxx.c Thu Aug 10 10:14:33 2000
    +++ linux-2.4.0-test7-pre5.acme/drivers/scsi/3w-xxxx.c Mon Aug 21 10:06:55 2000
    @@ -3,6 +3,7 @@

    Written By: Adam Radford <linux@3ware.com>
    Modifications By: Joel Jacobson <linux@3ware.com>
    + Arnaldo Carvalho de Melo <acme@conectiva.com.br>

    Copyright (C) 1999-2000 3ware Inc.

    @@ -64,6 +65,8 @@
    Bug fix so hot spare drives don't show up.
    1.02.00.002 - Fix bug with tw_setfeature() call that caused oops on some
    systems.
    + 08/21/00 - release previously allocated resources on failure at
    + tw_allocate_memory (acme)
    */

    #include <linux/module.h>
    @@ -410,35 +413,26 @@
    /* This function will allocate memory and check if it is 16 d-word aligned */
    int tw_allocate_memory(TW_Device_Extension *tw_dev, int request_id, int size, int which)
    {
    - u32 *virt_addr;
    + u32 *virt_addr = kmalloc(size, GFP_ATOMIC);

    dprintk(KERN_NOTICE "3w-xxxx: tw_allocate_memory()\n");

    + if (!virt_addr) {
    + printk(KERN_WARNING "3w-xxxx: tw_allocate_memory(): kmalloc() failed.\n");
    + return 1;
    + }
    +
    + if ((u32)virt_addr % TW_ALIGNMENT) {
    + kfree(virt_addr);
    + printk(KERN_WARNING "3w-xxxx: tw_allocate_memory(): Found unaligned address.\n");
    + return 1;
    + }
    +
    if (which == 0) {
    - /* Allocate command packet memory */
    - virt_addr = kmalloc(size, GFP_ATOMIC);
    - if (virt_addr == NULL) {
    - printk(KERN_WARNING "3w-xxxx: tw_allocate_memory(): kmalloc() failed.\n");
    - return 1;
    - }
    - if ((u32)virt_addr % TW_ALIGNMENT) {
    - printk(KERN_WARNING "3w-xxxx: tw_allocate_memory(): Found unaligned address.\n");
    - return 1;
    - }
    tw_dev->command_packet_virtual_address[request_id] = virt_addr;
    tw_dev->command_packet_physical_address[request_id] =
    virt_to_bus(virt_addr);
    } else {
    - /* Allocate generic buffer */
    - virt_addr = kmalloc(size, GFP_ATOMIC);
    - if (virt_addr == NULL) {
    - printk(KERN_WARNING "3w-xxxx: tw_allocate_memory(): kmalloc() failed.\n");
    - return 1;
    - }
    - if ((u32)virt_addr % TW_ALIGNMENT) {
    - printk(KERN_WARNING "3w-xxxx: tw_allocate_memory(): Found unaligned address.\n");
    - return 1;
    - }
    tw_dev->alignment_virtual_address[request_id] = virt_addr;
    tw_dev->alignment_physical_address[request_id] = virt_to_bus(virt_addr);
    }
    -
    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to majordomo@vger.kernel.org
    Please read the FAQ at http://www.tux.org/lkml/
    \
     
     \ /
      Last update: 2005-03-22 12:37    [W:8.609 / U:0.328 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site