提交 07002e99 编写于 作者: A Al Viro 提交者: Linus Torvalds

fix the dynamic allocation and probe in loop.c

Signed-off-by: NAl Viro <viro@zeniv.linux.org.uk>
Acked-by: NKen Chen <kenchen@google.com>
Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
上级 f1d1a842
...@@ -1317,18 +1317,6 @@ static long lo_compat_ioctl(struct file *file, unsigned int cmd, unsigned long a ...@@ -1317,18 +1317,6 @@ static long lo_compat_ioctl(struct file *file, unsigned int cmd, unsigned long a
} }
#endif #endif
static struct loop_device *loop_find_dev(int number)
{
struct loop_device *lo;
list_for_each_entry(lo, &loop_devices, lo_list) {
if (lo->lo_number == number)
return lo;
}
return NULL;
}
static struct loop_device *loop_init_one(int i);
static int lo_open(struct inode *inode, struct file *file) static int lo_open(struct inode *inode, struct file *file)
{ {
struct loop_device *lo = inode->i_bdev->bd_disk->private_data; struct loop_device *lo = inode->i_bdev->bd_disk->private_data;
...@@ -1337,11 +1325,6 @@ static int lo_open(struct inode *inode, struct file *file) ...@@ -1337,11 +1325,6 @@ static int lo_open(struct inode *inode, struct file *file)
lo->lo_refcnt++; lo->lo_refcnt++;
mutex_unlock(&lo->lo_ctl_mutex); mutex_unlock(&lo->lo_ctl_mutex);
mutex_lock(&loop_devices_mutex);
if (!loop_find_dev(lo->lo_number + 1))
loop_init_one(lo->lo_number + 1);
mutex_unlock(&loop_devices_mutex);
return 0; return 0;
} }
...@@ -1448,7 +1431,7 @@ static struct loop_device *loop_init_one(int i) ...@@ -1448,7 +1431,7 @@ static struct loop_device *loop_init_one(int i)
out_free_dev: out_free_dev:
kfree(lo); kfree(lo);
out: out:
return ERR_PTR(-ENOMEM); return NULL;
} }
static void loop_del_one(struct loop_device *lo) static void loop_del_one(struct loop_device *lo)
...@@ -1460,36 +1443,30 @@ static void loop_del_one(struct loop_device *lo) ...@@ -1460,36 +1443,30 @@ static void loop_del_one(struct loop_device *lo)
kfree(lo); kfree(lo);
} }
static int loop_lock(dev_t dev, void *data)
{
mutex_lock(&loop_devices_mutex);
return 0;
}
static struct kobject *loop_probe(dev_t dev, int *part, void *data) static struct kobject *loop_probe(dev_t dev, int *part, void *data)
{ {
unsigned int number = dev & MINORMASK; struct loop_device *lo = loop_init_one(dev & MINORMASK);
struct loop_device *lo; struct kobject *kobj;
mutex_lock(&loop_devices_mutex); kobj = lo ? get_disk(lo->lo_disk) : ERR_PTR(-ENOMEM);
lo = loop_find_dev(number);
if (lo == NULL)
lo = loop_init_one(number);
mutex_unlock(&loop_devices_mutex); mutex_unlock(&loop_devices_mutex);
*part = 0; *part = 0;
if (IS_ERR(lo)) return kobj;
return (void *)lo;
else
return &lo->lo_disk->kobj;
} }
static int __init loop_init(void) static int __init loop_init(void)
{ {
struct loop_device *lo;
if (register_blkdev(LOOP_MAJOR, "loop")) if (register_blkdev(LOOP_MAJOR, "loop"))
return -EIO; return -EIO;
blk_register_region(MKDEV(LOOP_MAJOR, 0), 1UL << MINORBITS, blk_register_region(MKDEV(LOOP_MAJOR, 0), 1UL << MINORBITS,
THIS_MODULE, loop_probe, NULL, NULL); THIS_MODULE, loop_probe, loop_lock, NULL);
lo = loop_init_one(0);
if (IS_ERR(lo))
goto out;
if (max_loop) { if (max_loop) {
printk(KERN_INFO "loop: the max_loop option is obsolete " printk(KERN_INFO "loop: the max_loop option is obsolete "
...@@ -1498,11 +1475,6 @@ static int __init loop_init(void) ...@@ -1498,11 +1475,6 @@ static int __init loop_init(void)
} }
printk(KERN_INFO "loop: module loaded\n"); printk(KERN_INFO "loop: module loaded\n");
return 0; return 0;
out:
unregister_blkdev(LOOP_MAJOR, "loop");
printk(KERN_ERR "loop: ran out of memory\n");
return -ENOMEM;
} }
static void __exit loop_exit(void) static void __exit loop_exit(void)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册