scsi/sr.c resource alloc checking
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH 1/1 scsi/sr.c resource alloc checking
Alan/Jens,
Please consider applying, a similar patch is already in 2.4. Insr_init we don't need zeroing the data allocated with scsi_init_malloc, as scsi_init_malloc already does this for us.
- Arnaldo
drivers/scsi/sr.c +33 -14
@@ -26,6 +26,8 @@* Modified by Jens Axboe <[email protected]> - support DVD-RAM * transparently and loose the GHOST hack * +* Modified by Arnaldo Carvalho de Melo <[email protected]> +* check resource allocation in sr_init and some cleanups - 2000/12/09 */ #include <linux/module.h>
@@ -70,10 +72,10 @@ sr_finish, sr_attach, sr_detach }; -Scsi_CD *scsi_CDs =NULL ; -static int *sr_sizes =NULL ; +Scsi_CD *scsi_CDs; +static int *sr_sizes; -static int *sr_blocksizes =NULL ; +static int *sr_blocksizes;static int sr_open (struct cdrom_device_info *,int );void get_sectorsize (int );
@@ -1113,16 +1115,21 @@ }if (scsi_CDs)return 0 ; - sr_template.dev_max = - sr_template.dev_noticed +SR_EXTRA_DEVS ; - scsi_CDs = (Scsi_CD *)scsi_init_malloc (sr_template.dev_max *sizeof (Scsi_CD),GFP_ATOMIC ); -memset (scsi_CDs,0 , sr_template.dev_max *sizeof (Scsi_CD)); - - sr_sizes = (int *)scsi_init_malloc (sr_template.dev_max *sizeof (int ),GFP_ATOMIC ); -memset (sr_sizes,0 , sr_template.dev_max *sizeof (int )); - - sr_blocksizes = (int *)scsi_init_malloc (sr_template.dev_max * -sizeof (int ),GFP_ATOMIC ); + sr_template.dev_max = sr_template.dev_noticed +SR_EXTRA_DEVS ; + scsi_CDs =scsi_init_malloc (sr_template.dev_max *sizeof (Scsi_CD), +GFP_ATOMIC ); +if (!scsi_CDs) + goto cleanup_register; + + sr_sizes =scsi_init_malloc (sr_template.dev_max *sizeof (int ), +GFP_ATOMIC ); +if (!sr_sizes) + goto cleanup_cds; + + sr_blocksizes =scsi_init_malloc (sr_template.dev_max *sizeof (int ), +GFP_ATOMIC ); +if (!sr_blocksizes) + goto cleanup_sizes;/* * These are good guesses for the time being.
@@ -1131,6 +1138,18 @@ sr_blocksizes[i] =2048 ; blksize_size[MAJOR_NR ] = sr_blocksizes;return 0 ; +cleanup_sizes: +scsi_init_free ((char *) sr_sizes, sr_template.dev_max *sizeof (int )); + sr_sizes =NULL ; +cleanup_cds: +scsi_init_free ((char *) scsi_CDs, + (sr_template.dev_noticed +SR_EXTRA_DEVS ) * +sizeof (Scsi_CD)); + scsi_CDs =NULL ; +cleanup_register: +unregister_blkdev (MAJOR_NR ,"sr" ); + sr_registered--; +return 1 ; }void sr_finish ()
@@ -1241,7 +1260,7 @@scsi_init_free ((char *) scsi_CDs, (sr_template.dev_noticed +SR_EXTRA_DEVS ) *sizeof (Scsi_CD)); - + scsi_CDs =NULL ;scsi_init_free ((char *) sr_sizes, sr_template.dev_max *sizeof (int )); sr_sizes =NULL ;
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
Please read the FAQ at http://www.tux.org/lkml/
PATCH 1/1 drivers/net/sbni.c irq release on failure
In reply to a message not in the archiveAlan/Yaroslav,
Please consider applying, a similar patch is already in 2.4.
- Arnaldo
drivers/net/sbni.c +1 -0
@@ -456,6 +456,7 @@if (dev->priv ==NULL ) { DP( printk("%s: cannot allocate memory\n", dev->name); ) +free_irq (dev->irq, dev);return -ENOMEM ; }
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH] drivers/net/sbni.c irq release on failure
Hi!
Quoted 3 lines · Arnaldo Carvalho de Melo
Alan/Yaroslav,
Please consider applying, a similar patch is already in 2.4.
I want to release new version of sbni driver soon (after QA procedures). This new version will be ported to 2.4 kernel. this version already have your patch applied. Thanks! :)
drivers/net/sbni.c line 462
Quoted 13 lines
- Arnaldo
drivers/net/sbni.c +1
-0@@ -456,6 +456,7 @@if (dev->priv ==NULL ) { DP( printk("%s: cannot allocate memory\n", dev->name); ) +free_irq (dev->irq, dev);return -ENOMEM ; }
.
Si vis pacem, para bellum
Granch ltd. Security Analyst
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
Please read the FAQ at http://www.tux.org/lkml/
PATCH 1/1 2.2: drivers/scsi/3c-xxxx.c resource release on failure
In reply to a message not in the archiveAlan/Adam,
Please consider applying, a similar patch is already in 2.4.
- Arnaldo
drivers/scsi/3w-xxxx.c +19 -23
@@ -3,6 +3,8 @@ Written By: Adam Radford <[email protected]> Modifications By: Joel Jacobson <[email protected]> + Arnaldo Carvalho de Melo <[email protected]> + Copyright (C) 1999-2000 3ware Inc.
@@ -64,6 +66,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. +12/09/2000 - release previously allocated resources on failure at +tw_allocate_memory (acme) */ #include <linux/module.h>
@@ -416,37 +420,29 @@/* 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); +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); + tw_dev->alignment_physical_address[request_id] = +virt_to_bus (virt_addr); }return 0 ; }/* End tw_allocate_memory() */
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
Please read the FAQ at http://www.tux.org/lkml/