diff options
author | Mark Brown <broonie@kernel.org> | 2019-06-18 20:12:47 +0200 |
---|---|---|
committer | Mark Brown <broonie@kernel.org> | 2019-06-18 20:12:47 +0200 |
commit | e1d700f7c94e755106749411706a38e39a93404b (patch) | |
tree | b1230cb7eba5a4ef28ed2cd2527d9ac78f06cc00 /drivers/block/loop.c | |
parent | regulator: qcom_spmi: Refactor get_mode/set_mode (diff) | |
parent | Linux 5.2-rc4 (diff) | |
download | linux-e1d700f7c94e755106749411706a38e39a93404b.tar.xz linux-e1d700f7c94e755106749411706a38e39a93404b.zip |
Merge tag 'v5.2-rc4' into regulator-5.3
Linux 5.2-rc4
Diffstat (limited to 'drivers/block/loop.c')
-rw-r--r-- | drivers/block/loop.c | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/drivers/block/loop.c b/drivers/block/loop.c index 102d79575895..f11b7dc16e9d 100644 --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -945,9 +945,20 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode, if (!file) goto out; + /* + * If we don't hold exclusive handle for the device, upgrade to it + * here to avoid changing device under exclusive owner. + */ + if (!(mode & FMODE_EXCL)) { + bdgrab(bdev); + error = blkdev_get(bdev, mode | FMODE_EXCL, loop_set_fd); + if (error) + goto out_putf; + } + error = mutex_lock_killable(&loop_ctl_mutex); if (error) - goto out_putf; + goto out_bdev; error = -EBUSY; if (lo->lo_state != Lo_unbound) @@ -1012,10 +1023,15 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode, mutex_unlock(&loop_ctl_mutex); if (partscan) loop_reread_partitions(lo, bdev); + if (!(mode & FMODE_EXCL)) + blkdev_put(bdev, mode | FMODE_EXCL); return 0; out_unlock: mutex_unlock(&loop_ctl_mutex); +out_bdev: + if (!(mode & FMODE_EXCL)) + blkdev_put(bdev, mode | FMODE_EXCL); out_putf: fput(file); out: |