Messages in this thread Patch in this message |  | | Date | Wed, 23 Aug 2000 12:20:21 -0300 | From | Arnaldo Carvalho de Melo <> | Subject | [PATCH] sr.c: handling resource allocation failure |
| |
Hi,
Please take a look and consider applying.
- Arnaldo
--- linux-2.4.0-test7-pre7/drivers/scsi/sr.c Wed Jul 19 01:40:47 2000 +++ linux-2.4.0-test7-pre7.acme/drivers/scsi/sr.c Wed Aug 23 09:34:00 2000 @@ -28,6 +28,9 @@ * Modified by Jens Axboe <axboe@suse.de> - support DVD-RAM * transparently and loose the GHOST hack * + * Modified by Arnaldo Carvalho de Melo <acme@conectiva.com.br> + * check resource allocation in sr_init + * */ #include <linux/module.h> @@ -713,16 +716,23 @@ sr_template.dev_max = sr_template.dev_noticed + SR_EXTRA_DEVS; scsi_CDs = (Scsi_CD *) kmalloc(sr_template.dev_max * sizeof(Scsi_CD), GFP_ATOMIC); + if (!scsi_CDs) + goto cleanup_devfs; memset(scsi_CDs, 0, sr_template.dev_max * sizeof(Scsi_CD)); sr_sizes = (int *) kmalloc(sr_template.dev_max * sizeof(int), GFP_ATOMIC); + if (!sr_sizes) + goto cleanup_cds; memset(sr_sizes, 0, sr_template.dev_max * sizeof(int)); sr_blocksizes = (int *) kmalloc(sr_template.dev_max * sizeof(int), GFP_ATOMIC); - + if (!sr_blocksizes) + goto cleanup_sizes; sr_hardsizes = (int *) kmalloc(sr_template.dev_max * sizeof(int), GFP_ATOMIC); + if (!sr_hardsizes) + goto cleanup_blocksizes; /* * These are good guesses for the time being. */ @@ -734,6 +744,16 @@ blksize_size[MAJOR_NR] = sr_blocksizes; hardsect_size[MAJOR_NR] = sr_hardsizes; return 0; +cleanup_blocksizes: + kfree(sr_blocksizes); +cleanup_sizes: + kfree(sr_sizes); +cleanup_cds: + kfree(scsi_CDs); +cleanup_devfs: + devfs_unregister_blkdev(MAJOR_NR, "sr"); + sr_registered--; + return 1; } void sr_finish() - 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/
|  |