Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8de64127 authored by Jan Kara's avatar Jan Kara Committed by Greg Kroah-Hartman
Browse files

loop: Push loop_ctl_mutex down to loop_get_status()



commit 4a5ce9ba5877e4640200d84a735361306ad1a1b8 upstream.

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: default avatarJan Kara <jack@suse.cz>
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent ed87dc66
Loading
Loading
Loading
Loading
+10 −27
Original line number Diff line number Diff line
@@ -1233,6 +1233,9 @@ loop_get_status(struct loop_device *lo, struct loop_info64 *info)
	struct kstat stat;
	int ret;

	ret = mutex_lock_killable_nested(&loop_ctl_mutex, 1);
	if (ret)
		return ret;
	if (lo->lo_state != Lo_bound) {
		mutex_unlock(&loop_ctl_mutex);
		return -ENXIO;
@@ -1347,10 +1350,8 @@ loop_get_status_old(struct loop_device *lo, struct loop_info __user *arg) {
	struct loop_info64 info64;
	int err;

	if (!arg) {
		mutex_unlock(&loop_ctl_mutex);
	if (!arg)
		return -EINVAL;
	}
	err = loop_get_status(lo, &info64);
	if (!err)
		err = loop_info64_to_old(&info64, &info);
@@ -1365,10 +1366,8 @@ loop_get_status64(struct loop_device *lo, struct loop_info64 __user *arg) {
	struct loop_info64 info64;
	int err;

	if (!arg) {
		mutex_unlock(&loop_ctl_mutex);
	if (!arg)
		return -EINVAL;
	}
	err = loop_get_status(lo, &info64);
	if (!err && copy_to_user(arg, &info64, sizeof(info64)))
		err = -EFAULT;
@@ -1478,12 +1477,7 @@ static int lo_ioctl(struct block_device *bdev, fmode_t mode,
		}
		break;
	case LOOP_GET_STATUS:
		err = mutex_lock_killable_nested(&loop_ctl_mutex, 1);
		if (err)
			return err;
		err = loop_get_status_old(lo, (struct loop_info __user *) arg);
		/* loop_get_status() unlocks loop_ctl_mutex */
		break;
		return loop_get_status_old(lo, (struct loop_info __user *) arg);
	case LOOP_SET_STATUS64:
		err = -EPERM;
		if ((mode & FMODE_WRITE) || capable(CAP_SYS_ADMIN)) {
@@ -1496,12 +1490,7 @@ static int lo_ioctl(struct block_device *bdev, fmode_t mode,
		}
		break;
	case LOOP_GET_STATUS64:
		err = mutex_lock_killable_nested(&loop_ctl_mutex, 1);
		if (err)
			return err;
		err = loop_get_status64(lo, (struct loop_info64 __user *) arg);
		/* loop_get_status() unlocks loop_ctl_mutex */
		break;
		return loop_get_status64(lo, (struct loop_info64 __user *) arg);
	case LOOP_SET_CAPACITY:
	case LOOP_SET_DIRECT_IO:
	case LOOP_SET_BLOCK_SIZE:
@@ -1626,10 +1615,8 @@ loop_get_status_compat(struct loop_device *lo,
	struct loop_info64 info64;
	int err;

	if (!arg) {
		mutex_unlock(&loop_ctl_mutex);
	if (!arg)
		return -EINVAL;
	}
	err = loop_get_status(lo, &info64);
	if (!err)
		err = loop_info64_to_compat(&info64, arg);
@@ -1652,12 +1639,8 @@ static int lo_compat_ioctl(struct block_device *bdev, fmode_t mode,
		}
		break;
	case LOOP_GET_STATUS:
		err = mutex_lock_killable(&loop_ctl_mutex);
		if (!err) {
		err = loop_get_status_compat(lo,
				     (struct compat_loop_info __user *)arg);
			/* loop_get_status() unlocks loop_ctl_mutex */
		}
		break;
	case LOOP_SET_CAPACITY:
	case LOOP_CLR_FD: