Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix the dynamic allocation and probe in loop.c

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Acked-by: Ken Chen <kenchen@google.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Al Viro and committed by
Linus Torvalds
07002e99 f1d1a842

+12 -40
+12 -40
drivers/block/loop.c
··· 1317 1317 } 1318 1318 #endif 1319 1319 1320 - static struct loop_device *loop_find_dev(int number) 1321 - { 1322 - struct loop_device *lo; 1323 - 1324 - list_for_each_entry(lo, &loop_devices, lo_list) { 1325 - if (lo->lo_number == number) 1326 - return lo; 1327 - } 1328 - return NULL; 1329 - } 1330 - 1331 - static struct loop_device *loop_init_one(int i); 1332 1320 static int lo_open(struct inode *inode, struct file *file) 1333 1321 { 1334 1322 struct loop_device *lo = inode->i_bdev->bd_disk->private_data; ··· 1324 1336 mutex_lock(&lo->lo_ctl_mutex); 1325 1337 lo->lo_refcnt++; 1326 1338 mutex_unlock(&lo->lo_ctl_mutex); 1327 - 1328 - mutex_lock(&loop_devices_mutex); 1329 - if (!loop_find_dev(lo->lo_number + 1)) 1330 - loop_init_one(lo->lo_number + 1); 1331 - mutex_unlock(&loop_devices_mutex); 1332 1339 1333 1340 return 0; 1334 1341 } ··· 1431 1448 out_free_dev: 1432 1449 kfree(lo); 1433 1450 out: 1434 - return ERR_PTR(-ENOMEM); 1451 + return NULL; 1435 1452 } 1436 1453 1437 1454 static void loop_del_one(struct loop_device *lo) ··· 1443 1460 kfree(lo); 1444 1461 } 1445 1462 1463 + static int loop_lock(dev_t dev, void *data) 1464 + { 1465 + mutex_lock(&loop_devices_mutex); 1466 + return 0; 1467 + } 1468 + 1446 1469 static struct kobject *loop_probe(dev_t dev, int *part, void *data) 1447 1470 { 1448 - unsigned int number = dev & MINORMASK; 1449 - struct loop_device *lo; 1471 + struct loop_device *lo = loop_init_one(dev & MINORMASK); 1472 + struct kobject *kobj; 1450 1473 1451 - mutex_lock(&loop_devices_mutex); 1452 - lo = loop_find_dev(number); 1453 - if (lo == NULL) 1454 - lo = loop_init_one(number); 1474 + kobj = lo ? get_disk(lo->lo_disk) : ERR_PTR(-ENOMEM); 1455 1475 mutex_unlock(&loop_devices_mutex); 1456 1476 1457 1477 *part = 0; 1458 - if (IS_ERR(lo)) 1459 - return (void *)lo; 1460 - else 1461 - return &lo->lo_disk->kobj; 1478 + return kobj; 1462 1479 } 1463 1480 1464 1481 static int __init loop_init(void) 1465 1482 { 1466 - struct loop_device *lo; 1467 - 1468 1483 if (register_blkdev(LOOP_MAJOR, "loop")) 1469 1484 return -EIO; 1470 1485 blk_register_region(MKDEV(LOOP_MAJOR, 0), 1UL << MINORBITS, 1471 - THIS_MODULE, loop_probe, NULL, NULL); 1472 - 1473 - lo = loop_init_one(0); 1474 - if (IS_ERR(lo)) 1475 - goto out; 1486 + THIS_MODULE, loop_probe, loop_lock, NULL); 1476 1487 1477 1488 if (max_loop) { 1478 1489 printk(KERN_INFO "loop: the max_loop option is obsolete " ··· 1475 1498 } 1476 1499 printk(KERN_INFO "loop: module loaded\n"); 1477 1500 return 0; 1478 - 1479 - out: 1480 - unregister_blkdev(LOOP_MAJOR, "loop"); 1481 - printk(KERN_ERR "loop: ran out of memory\n"); 1482 - return -ENOMEM; 1483 1501 } 1484 1502 1485 1503 static void __exit loop_exit(void)