diff options
author | Akinobu Mita <akinobu.mita@gmail.com> | 2006-10-17 03:10:27 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@g5.osdl.org> | 2006-10-17 11:18:48 -0400 |
commit | ea6f94dfe9db4d19a39e774cfafa5c9428a9fdbc (patch) | |
tree | 22c0b158dd9bf54e516eb7a9d6f50e3405b729d7 /drivers/block | |
parent | 3864c4894a7f4c03d69a90082a5bb0ab10e437ab (diff) |
[PATCH] rd: memory leak on rd_init() failure
If RAM disk driver initialization fails due to blk_alloc_queue() faulure, the
gendisk structs stored in rd_disks[] will not be freed completely.
This patch resolves that memory leak case by doing alloc_disk() and
blk_alloc_queue() at the same time.
Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'drivers/block')
-rw-r--r-- | drivers/block/rd.c | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/drivers/block/rd.c b/drivers/block/rd.c index a3f64bfe6b58..485aa87e9bcd 100644 --- a/drivers/block/rd.c +++ b/drivers/block/rd.c | |||
@@ -432,6 +432,12 @@ static int __init rd_init(void) | |||
432 | rd_disks[i] = alloc_disk(1); | 432 | rd_disks[i] = alloc_disk(1); |
433 | if (!rd_disks[i]) | 433 | if (!rd_disks[i]) |
434 | goto out; | 434 | goto out; |
435 | |||
436 | rd_queue[i] = blk_alloc_queue(GFP_KERNEL); | ||
437 | if (!rd_queue[i]) { | ||
438 | put_disk(rd_disks[i]); | ||
439 | goto out; | ||
440 | } | ||
435 | } | 441 | } |
436 | 442 | ||
437 | if (register_blkdev(RAMDISK_MAJOR, "ramdisk")) { | 443 | if (register_blkdev(RAMDISK_MAJOR, "ramdisk")) { |
@@ -442,10 +448,6 @@ static int __init rd_init(void) | |||
442 | for (i = 0; i < CONFIG_BLK_DEV_RAM_COUNT; i++) { | 448 | for (i = 0; i < CONFIG_BLK_DEV_RAM_COUNT; i++) { |
443 | struct gendisk *disk = rd_disks[i]; | 449 | struct gendisk *disk = rd_disks[i]; |
444 | 450 | ||
445 | rd_queue[i] = blk_alloc_queue(GFP_KERNEL); | ||
446 | if (!rd_queue[i]) | ||
447 | goto out_queue; | ||
448 | |||
449 | blk_queue_make_request(rd_queue[i], &rd_make_request); | 451 | blk_queue_make_request(rd_queue[i], &rd_make_request); |
450 | blk_queue_hardsect_size(rd_queue[i], rd_blocksize); | 452 | blk_queue_hardsect_size(rd_queue[i], rd_blocksize); |
451 | 453 | ||
@@ -466,8 +468,6 @@ static int __init rd_init(void) | |||
466 | CONFIG_BLK_DEV_RAM_COUNT, rd_size, rd_blocksize); | 468 | CONFIG_BLK_DEV_RAM_COUNT, rd_size, rd_blocksize); |
467 | 469 | ||
468 | return 0; | 470 | return 0; |
469 | out_queue: | ||
470 | unregister_blkdev(RAMDISK_MAJOR, "ramdisk"); | ||
471 | out: | 471 | out: |
472 | while (i--) { | 472 | while (i--) { |
473 | put_disk(rd_disks[i]); | 473 | put_disk(rd_disks[i]); |