@@ -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)
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(-)