summaryrefslogtreecommitdiffstats
path: root/drivers/block/rd.c
diff options
context:
space:
mode:
authorAkinobu Mita <akinobu.mita@gmail.com>2006-10-17 00:10:27 -0700
committerLinus Torvalds <torvalds@g5.osdl.org>2006-10-17 08:18:48 -0700
commitea6f94dfe9db4d19a39e774cfafa5c9428a9fdbc (patch)
tree22c0b158dd9bf54e516eb7a9d6f50e3405b729d7 /drivers/block/rd.c
parent3864c4894a7f4c03d69a90082a5bb0ab10e437ab (diff)
downloadop-kernel-dev-ea6f94dfe9db4d19a39e774cfafa5c9428a9fdbc.zip
op-kernel-dev-ea6f94dfe9db4d19a39e774cfafa5c9428a9fdbc.tar.gz
[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/rd.c')
-rw-r--r--drivers/block/rd.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/drivers/block/rd.c b/drivers/block/rd.c
index a3f64bf..485aa87 100644
--- a/drivers/block/rd.c
+++ b/drivers/block/rd.c
@@ -432,6 +432,12 @@ static int __init rd_init(void)
rd_disks[i] = alloc_disk(1);
if (!rd_disks[i])
goto out;
+
+ rd_queue[i] = blk_alloc_queue(GFP_KERNEL);
+ if (!rd_queue[i]) {
+ put_disk(rd_disks[i]);
+ goto out;
+ }
}
if (register_blkdev(RAMDISK_MAJOR, "ramdisk")) {
@@ -442,10 +448,6 @@ static int __init rd_init(void)
for (i = 0; i < CONFIG_BLK_DEV_RAM_COUNT; i++) {
struct gendisk *disk = rd_disks[i];
- rd_queue[i] = blk_alloc_queue(GFP_KERNEL);
- if (!rd_queue[i])
- goto out_queue;
-
blk_queue_make_request(rd_queue[i], &rd_make_request);
blk_queue_hardsect_size(rd_queue[i], rd_blocksize);
@@ -466,8 +468,6 @@ static int __init rd_init(void)
CONFIG_BLK_DEV_RAM_COUNT, rd_size, rd_blocksize);
return 0;
-out_queue:
- unregister_blkdev(RAMDISK_MAJOR, "ramdisk");
out:
while (i--) {
put_disk(rd_disks[i]);
OpenPOWER on IntegriCloud