aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/block/loop.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/block/loop.c')
-rw-r--r--drivers/block/loop.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/drivers/block/loop.c b/drivers/block/loop.c
index cd1e17460f03..b2955b3f2cbc 100644
--- a/drivers/block/loop.c
+++ b/drivers/block/loop.c
@@ -924,6 +924,11 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
924 lo->lo_flags |= LO_FLAGS_PARTSCAN; 924 lo->lo_flags |= LO_FLAGS_PARTSCAN;
925 if (lo->lo_flags & LO_FLAGS_PARTSCAN) 925 if (lo->lo_flags & LO_FLAGS_PARTSCAN)
926 ioctl_by_bdev(bdev, BLKRRPART, 0); 926 ioctl_by_bdev(bdev, BLKRRPART, 0);
927
928 /* Grab the block_device to prevent its destruction after we
929 * put /dev/loopXX inode. Later in loop_clr_fd() we bdput(bdev).
930 */
931 bdgrab(bdev);
927 return 0; 932 return 0;
928 933
929out_clr: 934out_clr:
@@ -1033,8 +1038,10 @@ static int loop_clr_fd(struct loop_device *lo)
1033 memset(lo->lo_encrypt_key, 0, LO_KEY_SIZE); 1038 memset(lo->lo_encrypt_key, 0, LO_KEY_SIZE);
1034 memset(lo->lo_crypt_name, 0, LO_NAME_SIZE); 1039 memset(lo->lo_crypt_name, 0, LO_NAME_SIZE);
1035 memset(lo->lo_file_name, 0, LO_NAME_SIZE); 1040 memset(lo->lo_file_name, 0, LO_NAME_SIZE);
1036 if (bdev) 1041 if (bdev) {
1042 bdput(bdev);
1037 invalidate_bdev(bdev); 1043 invalidate_bdev(bdev);
1044 }
1038 set_capacity(lo->lo_disk, 0); 1045 set_capacity(lo->lo_disk, 0);
1039 loop_sysfs_exit(lo); 1046 loop_sysfs_exit(lo);
1040 if (bdev) { 1047 if (bdev) {
@@ -1625,6 +1632,7 @@ static int loop_add(struct loop_device **l, int i)
1625 goto out_free_dev; 1632 goto out_free_dev;
1626 i = err; 1633 i = err;
1627 1634
1635 err = -ENOMEM;
1628 lo->lo_queue = blk_alloc_queue(GFP_KERNEL); 1636 lo->lo_queue = blk_alloc_queue(GFP_KERNEL);
1629 if (!lo->lo_queue) 1637 if (!lo->lo_queue)
1630 goto out_free_dev; 1638 goto out_free_dev;