@@ -704,19 +704,22 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
error = mutex_lock_killable(&lo->lo_mutex);
if (error)
return error;
- error = -ENXIO;
- if (lo->lo_state != Lo_bound)
+ if (lo->lo_state != Lo_bound) {
+ error = -ENXIO;
goto out_err;
+ }
/* the loop device has to be read-only */
- error = -EINVAL;
- if (!(lo->lo_flags & LO_FLAGS_READ_ONLY))
+ if (!(lo->lo_flags & LO_FLAGS_READ_ONLY)) {
+ error = -EINVAL;
goto out_err;
+ }
- error = -EBADF;
file = fget(arg);
- if (!file)
+ if (!file) {
+ error = -EBADF;
goto out_err;
+ }
error = loop_validate_file(file, bdev);
if (error)
@@ -724,11 +727,11 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
old_file = lo->lo_backing_file;
- error = -EINVAL;
-
/* size of the new backing store needs to be the same */
- if (get_loop_size(lo, file) != get_loop_size(lo, old_file))
+ if (get_loop_size(lo, file) != get_loop_size(lo, old_file)) {
+ error = -EINVAL;
goto out_err;
+ }
/* and ... switch */
blk_mq_freeze_queue(lo->lo_queue);
The function loop_change_fd() set error = -ENXIO before checking loop state, error = -EINVAL before checking loop flags, error = -EBADF before calling fget and error = -EINVAL before comparing the old file size to the new file file. 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 | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-)