diff mbox series

[RFC,12/20] loop: cleanup lo_ioctl()

Message ID 20210202053552.4844-13-chaitanya.kulkarni@wdc.com (mailing list archive)
State New, archived
Headers show
Series loop: cleanup and small improvement | expand

Commit Message

Chaitanya Kulkarni Feb. 2, 2021, 5:35 a.m. UTC
Instead of storing the return values into the err variable just return
the err from switch cases, since we don't do anything after switch with
that error but return. This also removes the need for the local
variable err in lo_ioctl(). Instead of declaring config variable twice
in the set_fd and configire switch cases declare and initialize the loop
config variabel that removes the need for memset. Also, move status64
switch case near to set status case.

No functional change in this patch.

Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
---
 drivers/block/loop.c | 38 +++++++++++---------------------------
 1 file changed, 11 insertions(+), 27 deletions(-)
diff mbox series

Patch

diff --git a/drivers/block/loop.c b/drivers/block/loop.c
index d9cd0ac3d947..bc074ad00eaf 100644
--- a/drivers/block/loop.c
+++ b/drivers/block/loop.c
@@ -1660,48 +1660,35 @@  static int lo_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd,
 {
 	struct loop_device *lo = bdev->bd_disk->private_data;
 	void __user *argp = (void __user *) arg;
-	int err;
+	struct loop_config config = { };
 
 	switch (cmd) {
-	case LOOP_SET_FD: {
+	case LOOP_SET_FD:
 		/*
 		 * Legacy case - pass in a zeroed out struct loop_config with
 		 * only the file descriptor set , which corresponds with the
 		 * default parameters we'd have used otherwise.
 		 */
-		struct loop_config config;
-
-		memset(&config, 0, sizeof(config));
 		config.fd = arg;
-
 		return loop_configure(lo, mode, bdev, &config);
-	}
-	case LOOP_CONFIGURE: {
-		struct loop_config config;
-
+	case LOOP_CONFIGURE:
 		if (copy_from_user(&config, argp, sizeof(config)))
 			return -EFAULT;
-
 		return loop_configure(lo, mode, bdev, &config);
-	}
 	case LOOP_CHANGE_FD:
 		return loop_change_fd(lo, bdev, arg);
 	case LOOP_CLR_FD:
 		return loop_clr_fd(lo);
 	case LOOP_SET_STATUS:
-		err = -EPERM;
-		if ((mode & FMODE_WRITE) || capable(CAP_SYS_ADMIN)) {
-			err = loop_set_status_old(lo, argp);
-		}
-		break;
+		if ((mode & FMODE_WRITE) || capable(CAP_SYS_ADMIN))
+			return loop_set_status_old(lo, argp);
+		return -EPERM;
+	case LOOP_SET_STATUS64:
+		if ((mode & FMODE_WRITE) || capable(CAP_SYS_ADMIN))
+			return loop_set_status64(lo, argp);
+		return -EPERM;
 	case LOOP_GET_STATUS:
 		return loop_get_status_old(lo, argp);
-	case LOOP_SET_STATUS64:
-		err = -EPERM;
-		if ((mode & FMODE_WRITE) || capable(CAP_SYS_ADMIN)) {
-			err = loop_set_status64(lo, argp);
-		}
-		break;
 	case LOOP_GET_STATUS64:
 		return loop_get_status64(lo, argp);
 	case LOOP_SET_CAPACITY:
@@ -1711,11 +1698,8 @@  static int lo_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd,
 			return -EPERM;
 		fallthrough;
 	default:
-		err = lo_simple_ioctl(lo, cmd, arg);
-		break;
+		return lo_simple_ioctl(lo, cmd, arg);
 	}
-
-	return err;
 }
 
 #ifdef CONFIG_COMPAT