1 From b1a6650406875b9097a032eed89af50682fe1160 Mon Sep 17 00:00:00 2001
2 From: Guo Chao <yan@linux.vnet.ibm.com>
3 Date: Thu, 21 Feb 2013 15:16:49 -0800
4 Subject: loopdev: remove an user triggerable oops
6 From: Guo Chao <yan@linux.vnet.ibm.com>
8 commit b1a6650406875b9097a032eed89af50682fe1160 upstream.
10 When loopdev is built as module and we pass an invalid parameter,
11 loop_init() will return directly without deregister misc device, which
12 will cause an oops when insert loop module next time because we left some
13 garbage in the misc device list.
16 sudo modprobe loop max_part=1024
17 (failed due to invalid parameter)
21 Clean up nicely to avoid such oops.
23 Signed-off-by: Guo Chao <yan@linux.vnet.ibm.com>
24 Cc: Alexander Viro <viro@zeniv.linux.org.uk>
25 Cc: Guo Chao <yan@linux.vnet.ibm.com>
26 Cc: M. Hindess <hindessm@uk.ibm.com>
27 Cc: Nikanth Karthikesan <knikanth@suse.de>
28 Cc: Jens Axboe <axboe@kernel.dk>
29 Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
30 Signed-off-by: Jens Axboe <axboe@kernel.dk>
31 Acked-by: Jeff Mahoney <jeffm@suse.com>
32 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
35 drivers/block/loop.c | 22 ++++++++++++++++------
36 1 file changed, 16 insertions(+), 6 deletions(-)
38 --- a/drivers/block/loop.c
39 +++ b/drivers/block/loop.c
40 @@ -1856,11 +1856,15 @@ static int __init loop_init(void)
41 max_part = (1UL << part_shift) - 1;
44 - if ((1UL << part_shift) > DISK_MAX_PARTS)
46 + if ((1UL << part_shift) > DISK_MAX_PARTS) {
51 - if (max_loop > 1UL << (MINORBITS - part_shift))
53 + if (max_loop > 1UL << (MINORBITS - part_shift)) {
59 * If max_loop is specified, create that many devices upfront.
60 @@ -1878,8 +1882,10 @@ static int __init loop_init(void)
61 range = 1UL << MINORBITS;
64 - if (register_blkdev(LOOP_MAJOR, "loop"))
66 + if (register_blkdev(LOOP_MAJOR, "loop")) {
71 blk_register_region(MKDEV(LOOP_MAJOR, 0), range,
72 THIS_MODULE, loop_probe, NULL, NULL);
73 @@ -1892,6 +1898,10 @@ static int __init loop_init(void)
75 printk(KERN_INFO "loop: module loaded\n");
79 + misc_deregister(&loop_misc);
83 static int loop_exit_cb(int id, void *ptr, void *data)