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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxx>
---
 drivers/block/loop.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

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




[Index of Archives]     [Linux RAID]     [Linux SCSI]     [Linux ATA RAID]     [IDE]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Device Mapper]

  Powered by Linux