diff options
Diffstat (limited to 'drivers/block/loop.c')
-rw-r--r-- | drivers/block/loop.c | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/drivers/block/loop.c b/drivers/block/loop.c index fe5f6403417f..2c127f9c3f3b 100644 --- a/drivers/block/loop.c +++ b/drivers/block/loop.c | |||
@@ -922,6 +922,11 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode, | |||
922 | lo->lo_flags |= LO_FLAGS_PARTSCAN; | 922 | lo->lo_flags |= LO_FLAGS_PARTSCAN; |
923 | if (lo->lo_flags & LO_FLAGS_PARTSCAN) | 923 | if (lo->lo_flags & LO_FLAGS_PARTSCAN) |
924 | ioctl_by_bdev(bdev, BLKRRPART, 0); | 924 | ioctl_by_bdev(bdev, BLKRRPART, 0); |
925 | |||
926 | /* Grab the block_device to prevent its destruction after we | ||
927 | * put /dev/loopXX inode. Later in loop_clr_fd() we bdput(bdev). | ||
928 | */ | ||
929 | bdgrab(bdev); | ||
925 | return 0; | 930 | return 0; |
926 | 931 | ||
927 | out_clr: | 932 | out_clr: |
@@ -1031,8 +1036,10 @@ static int loop_clr_fd(struct loop_device *lo) | |||
1031 | memset(lo->lo_encrypt_key, 0, LO_KEY_SIZE); | 1036 | memset(lo->lo_encrypt_key, 0, LO_KEY_SIZE); |
1032 | memset(lo->lo_crypt_name, 0, LO_NAME_SIZE); | 1037 | memset(lo->lo_crypt_name, 0, LO_NAME_SIZE); |
1033 | memset(lo->lo_file_name, 0, LO_NAME_SIZE); | 1038 | memset(lo->lo_file_name, 0, LO_NAME_SIZE); |
1034 | if (bdev) | 1039 | if (bdev) { |
1040 | bdput(bdev); | ||
1035 | invalidate_bdev(bdev); | 1041 | invalidate_bdev(bdev); |
1042 | } | ||
1036 | set_capacity(lo->lo_disk, 0); | 1043 | set_capacity(lo->lo_disk, 0); |
1037 | loop_sysfs_exit(lo); | 1044 | loop_sysfs_exit(lo); |
1038 | if (bdev) { | 1045 | if (bdev) { |