diff mbox series

[RFC,18/20] loop: configure set err at actual error condition

Message ID 20210202053552.4844-19-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
The function loop_configure() set error = -EBADF before calling fget(),
error = -EBUSY before checking the state. None of these error values are
reused for the above conditions.

Conditionally set the error after we actually know that error condition
is true instead of setting it before the if check.

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

Patch

diff --git a/drivers/block/loop.c b/drivers/block/loop.c
index 89f9c73bb2af..d99ae348e4e2 100644
--- a/drivers/block/loop.c
+++ b/drivers/block/loop.c
@@ -1076,10 +1076,11 @@  static int loop_configure(struct loop_device *lo, fmode_t mode,
 	/* This is safe, since we have a reference from open(). */
 	__module_get(THIS_MODULE);
 
-	error = -EBADF;
 	file = fget(config->fd);
-	if (!file)
+	if (!file) {
+		error = -EBADF;
 		goto out;
+	}
 
 	/*
 	 * If we don't hold exclusive handle for the device, upgrade to it
@@ -1095,9 +1096,10 @@  static int loop_configure(struct loop_device *lo, fmode_t mode,
 	if (error)
 		goto out_bdev;
 
-	error = -EBUSY;
-	if (lo->lo_state != Lo_unbound)
+	if (lo->lo_state != Lo_unbound) {
+		error = -EBUSY;
 		goto out_unlock;
+	}
 
 	error = loop_validate_file(file, bdev);
 	if (error)