All of lore.kernel.org
 help / color / mirror / Atom feed
From: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
To: linux-block@vger.kernel.org
Cc: axboe@kernel.dk, Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
Subject: [RFC PATCH 12/20] loop: cleanup lo_ioctl()
Date: Mon,  1 Feb 2021 21:35:44 -0800	[thread overview]
Message-ID: <20210202053552.4844-13-chaitanya.kulkarni@wdc.com> (raw)
In-Reply-To: <20210202053552.4844-1-chaitanya.kulkarni@wdc.com>

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 --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
-- 
2.22.1


  parent reply	other threads:[~2021-02-02  5:38 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-02  5:35 [RFC PATCH 00/20] loop: cleanup and small improvement Chaitanya Kulkarni
2021-02-02  5:35 ` [RFC PATCH 01/20] loop: use uniform alignment for struct members Chaitanya Kulkarni
2021-02-02  5:35 ` [RFC PATCH 02/20] loop: add lockdep assert in loop_add() Chaitanya Kulkarni
2021-02-02  5:35 ` [RFC PATCH 03/20] loop: add lockdep assert in loop_lookup() Chaitanya Kulkarni
2021-02-02  5:35 ` [RFC PATCH 04/20] loop: allow user to set the queue depth Chaitanya Kulkarni
2021-02-02  5:35 ` [RFC PATCH 05/20] loop: use snprintf for XXX_show() Chaitanya Kulkarni
2021-02-02 11:05   ` Johannes Thumshirn
2021-02-02 19:56     ` Chaitanya Kulkarni
2021-02-02  5:35 ` [RFC PATCH 06/20] loop: add newline after variable declaration Chaitanya Kulkarni
2021-02-02  5:35 ` [RFC PATCH 07/20] loop: use uniform variable declaration style Chaitanya Kulkarni
2021-02-02  5:35 ` [RFC PATCH 08/20] loop: use uniform function header style Chaitanya Kulkarni
2021-02-02  5:35 ` [RFC PATCH 09/20] loop: remove extra variable in lo_fallocate() Chaitanya Kulkarni
2021-02-02 11:50   ` Johannes Thumshirn
2021-02-02  5:35 ` [RFC PATCH 10/20] loop: remove extra variable in lo_req_flush Chaitanya Kulkarni
2021-02-02 11:50   ` Johannes Thumshirn
2021-02-02  5:35 ` [RFC PATCH 11/20] loop: remove local variable in lo_compat_ioctl Chaitanya Kulkarni
2021-02-02 11:52   ` Johannes Thumshirn
2021-02-02  5:35 ` Chaitanya Kulkarni [this message]
2021-02-02  5:35 ` [RFC PATCH 13/20] loop: remove memset in info64 to compat Chaitanya Kulkarni
2021-02-02 11:55   ` Johannes Thumshirn
2021-02-02  5:35 ` [RFC PATCH 14/20] loop: remove memset in info64 from compat Chaitanya Kulkarni
2021-02-02 11:55   ` Johannes Thumshirn
2021-02-02  5:35 ` [RFC PATCH 15/20] loop: remove memset in loop_info64_from_old() Chaitanya Kulkarni
2021-02-02 11:58   ` Johannes Thumshirn
2021-02-02  5:35 ` [RFC PATCH 16/20] loop: remove memset in loop_info64_to_old() Chaitanya Kulkarni
2021-02-02 11:59   ` Johannes Thumshirn
2021-02-02  5:35 ` [RFC PATCH 17/20] loop: change fd set err at actual error condition Chaitanya Kulkarni
2021-02-02  5:35 ` [RFC PATCH 18/20] loop: configure " Chaitanya Kulkarni
2021-02-02  5:35 ` [RFC PATCH 19/20] loop: set error value in case of actual error Chaitanya Kulkarni
2021-02-02  5:35 ` [RFC PATCH 20/20] loop: remove the extra line in declaration Chaitanya Kulkarni
2021-02-02 12:07   ` Johannes Thumshirn

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210202053552.4844-13-chaitanya.kulkarni@wdc.com \
    --to=chaitanya.kulkarni@wdc.com \
    --cc=axboe@kernel.dk \
    --cc=linux-block@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.