loop: Push loop_ctl_mutex down to loop_get_status()

Push loop_ctl_mutex down to loop_get_status() to avoid the unusual
convention that the function gets called with loop_ctl_mutex held and
releases it.

Signed-off-by: Jan Kara <jack@suse.cz>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
This commit is contained in:
Jan Kara 2018-11-08 14:01:08 +01:00 committed by Jens Axboe
parent 7ccd0791d9
commit 4a5ce9ba58

View File

@ -1232,6 +1232,9 @@ loop_get_status(struct loop_device *lo, struct loop_info64 *info)
struct kstat stat; struct kstat stat;
int ret; int ret;
ret = mutex_lock_killable_nested(&loop_ctl_mutex, 1);
if (ret)
return ret;
if (lo->lo_state != Lo_bound) { if (lo->lo_state != Lo_bound) {
mutex_unlock(&loop_ctl_mutex); mutex_unlock(&loop_ctl_mutex);
return -ENXIO; return -ENXIO;
@ -1346,10 +1349,8 @@ loop_get_status_old(struct loop_device *lo, struct loop_info __user *arg) {
struct loop_info64 info64; struct loop_info64 info64;
int err; int err;
if (!arg) { if (!arg)
mutex_unlock(&loop_ctl_mutex);
return -EINVAL; return -EINVAL;
}
err = loop_get_status(lo, &info64); err = loop_get_status(lo, &info64);
if (!err) if (!err)
err = loop_info64_to_old(&info64, &info); err = loop_info64_to_old(&info64, &info);
@ -1364,10 +1365,8 @@ loop_get_status64(struct loop_device *lo, struct loop_info64 __user *arg) {
struct loop_info64 info64; struct loop_info64 info64;
int err; int err;
if (!arg) { if (!arg)
mutex_unlock(&loop_ctl_mutex);
return -EINVAL; return -EINVAL;
}
err = loop_get_status(lo, &info64); err = loop_get_status(lo, &info64);
if (!err && copy_to_user(arg, &info64, sizeof(info64))) if (!err && copy_to_user(arg, &info64, sizeof(info64)))
err = -EFAULT; err = -EFAULT;
@ -1477,12 +1476,7 @@ static int lo_ioctl(struct block_device *bdev, fmode_t mode,
} }
break; break;
case LOOP_GET_STATUS: case LOOP_GET_STATUS:
err = mutex_lock_killable_nested(&loop_ctl_mutex, 1); return loop_get_status_old(lo, (struct loop_info __user *) arg);
if (err)
return err;
err = loop_get_status_old(lo, (struct loop_info __user *) arg);
/* loop_get_status() unlocks loop_ctl_mutex */
break;
case LOOP_SET_STATUS64: case LOOP_SET_STATUS64:
err = -EPERM; err = -EPERM;
if ((mode & FMODE_WRITE) || capable(CAP_SYS_ADMIN)) { if ((mode & FMODE_WRITE) || capable(CAP_SYS_ADMIN)) {
@ -1495,12 +1489,7 @@ static int lo_ioctl(struct block_device *bdev, fmode_t mode,
} }
break; break;
case LOOP_GET_STATUS64: case LOOP_GET_STATUS64:
err = mutex_lock_killable_nested(&loop_ctl_mutex, 1); return loop_get_status64(lo, (struct loop_info64 __user *) arg);
if (err)
return err;
err = loop_get_status64(lo, (struct loop_info64 __user *) arg);
/* loop_get_status() unlocks loop_ctl_mutex */
break;
case LOOP_SET_CAPACITY: case LOOP_SET_CAPACITY:
case LOOP_SET_DIRECT_IO: case LOOP_SET_DIRECT_IO:
case LOOP_SET_BLOCK_SIZE: case LOOP_SET_BLOCK_SIZE:
@ -1625,10 +1614,8 @@ loop_get_status_compat(struct loop_device *lo,
struct loop_info64 info64; struct loop_info64 info64;
int err; int err;
if (!arg) { if (!arg)
mutex_unlock(&loop_ctl_mutex);
return -EINVAL; return -EINVAL;
}
err = loop_get_status(lo, &info64); err = loop_get_status(lo, &info64);
if (!err) if (!err)
err = loop_info64_to_compat(&info64, arg); err = loop_info64_to_compat(&info64, arg);
@ -1651,12 +1638,8 @@ static int lo_compat_ioctl(struct block_device *bdev, fmode_t mode,
} }
break; break;
case LOOP_GET_STATUS: case LOOP_GET_STATUS:
err = mutex_lock_killable(&loop_ctl_mutex); err = loop_get_status_compat(lo,
if (!err) { (struct compat_loop_info __user *)arg);
err = loop_get_status_compat(lo,
(struct compat_loop_info __user *)arg);
/* loop_get_status() unlocks loop_ctl_mutex */
}
break; break;
case LOOP_SET_CAPACITY: case LOOP_SET_CAPACITY:
case LOOP_CLR_FD: case LOOP_CLR_FD: