diff options
author | Guo Chao <yan@linux.vnet.ibm.com> | 2013-02-21 18:16:49 -0500 |
---|---|---|
committer | Jens Axboe <axboe@kernel.dk> | 2013-02-22 04:43:22 -0500 |
commit | b1a6650406875b9097a032eed89af50682fe1160 (patch) | |
tree | 2521139daec844942ca85e30c86c0218cc8f7a52 | |
parent | 7b0576a3d835b4d46ed85d817ce016e90bf293a3 (diff) |
loopdev: remove an user triggerable oops
When loopdev is built as module and we pass an invalid parameter,
loop_init() will return directly without deregister misc device, which
will cause an oops when insert loop module next time because we left some
garbage in the misc device list.
Test case:
sudo modprobe loop max_part=1024
(failed due to invalid parameter)
sudo modprobe loop
(oops)
Clean up nicely to avoid such oops.
Signed-off-by: Guo Chao <yan@linux.vnet.ibm.com>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: Guo Chao <yan@linux.vnet.ibm.com>
Cc: M. Hindess <hindessm@uk.ibm.com>
Cc: Nikanth Karthikesan <knikanth@suse.de>
Cc: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
-rw-r--r-- | drivers/block/loop.c | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/drivers/block/loop.c b/drivers/block/loop.c index 6579f69fd7a4..1b1b0c981a85 100644 --- a/drivers/block/loop.c +++ b/drivers/block/loop.c | |||
@@ -1844,11 +1844,15 @@ static int __init loop_init(void) | |||
1844 | max_part = (1UL << part_shift) - 1; | 1844 | max_part = (1UL << part_shift) - 1; |
1845 | } | 1845 | } |
1846 | 1846 | ||
1847 | if ((1UL << part_shift) > DISK_MAX_PARTS) | 1847 | if ((1UL << part_shift) > DISK_MAX_PARTS) { |
1848 | return -EINVAL; | 1848 | err = -EINVAL; |
1849 | goto misc_out; | ||
1850 | } | ||
1849 | 1851 | ||
1850 | if (max_loop > 1UL << (MINORBITS - part_shift)) | 1852 | if (max_loop > 1UL << (MINORBITS - part_shift)) { |
1851 | return -EINVAL; | 1853 | err = -EINVAL; |
1854 | goto misc_out; | ||
1855 | } | ||
1852 | 1856 | ||
1853 | /* | 1857 | /* |
1854 | * If max_loop is specified, create that many devices upfront. | 1858 | * If max_loop is specified, create that many devices upfront. |
@@ -1866,8 +1870,10 @@ static int __init loop_init(void) | |||
1866 | range = 1UL << MINORBITS; | 1870 | range = 1UL << MINORBITS; |
1867 | } | 1871 | } |
1868 | 1872 | ||
1869 | if (register_blkdev(LOOP_MAJOR, "loop")) | 1873 | if (register_blkdev(LOOP_MAJOR, "loop")) { |
1870 | return -EIO; | 1874 | err = -EIO; |
1875 | goto misc_out; | ||
1876 | } | ||
1871 | 1877 | ||
1872 | blk_register_region(MKDEV(LOOP_MAJOR, 0), range, | 1878 | blk_register_region(MKDEV(LOOP_MAJOR, 0), range, |
1873 | THIS_MODULE, loop_probe, NULL, NULL); | 1879 | THIS_MODULE, loop_probe, NULL, NULL); |
@@ -1880,6 +1886,10 @@ static int __init loop_init(void) | |||
1880 | 1886 | ||
1881 | printk(KERN_INFO "loop: module loaded\n"); | 1887 | printk(KERN_INFO "loop: module loaded\n"); |
1882 | return 0; | 1888 | return 0; |
1889 | |||
1890 | misc_out: | ||
1891 | misc_deregister(&loop_misc); | ||
1892 | return err; | ||
1883 | } | 1893 | } |
1884 | 1894 | ||
1885 | static int loop_exit_cb(int id, void *ptr, void *data) | 1895 | static int loop_exit_cb(int id, void *ptr, void *data) |