Skip to contentSkip to conversation

btrfs: Consolidate btrfs_previous_item ret val handling in btrfs_shrink_device

PATCH In review Nikolay Borisov 3 participants 3 messages Dec 17, 2020 – Dec 21, 2020 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 btrfs: Consolidate btrfs_previous_item ret val handling in btrfs_shrink_device

Instead of having 3 'if' to handle non-null return value consolidate this in 1 'if (ret)'. That way the code is more obvious:

- Always drop dlete_unused_bgs_mutex if ret is non null
- If ret is negative -> goto done
- If it's 1 -> reset ret to 0, release the path and finish the loop.

---
 fs/btrfs/volumes.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
fs/btrfs/volumes.c +3 -4
index 7930e1c78c45..a34eded1bfbe 100644
@@ -4667,11 +4667,10 @@ int btrfs_shrink_device(struct btrfs_device *device, u64 new_size)
 		}
 
 		ret = btrfs_previous_item(root, path, 0, key.type);
-		if (ret)
-			mutex_unlock(&fs_info->delete_unused_bgs_mutex);
-		if (ret < 0)
-			goto done;
 		if (ret) {
+			mutex_unlock(&fs_info->delete_unused_bgs_mutex);
+			if (ret < 0)
+				goto done;
 			ret = 0;
 			btrfs_release_path(path);
 			break;
Signature · 1 line
2.25.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Nikolay Borisov

Instead of having 3 'if' to handle non-null return value consolidate this in 1 'if (ret)'. That way the code is more obvious:

- Always drop dlete_unused_bgs_mutex if ret is non null
- If ret is negative -> goto done
- If it's 1 -> reset ret to 0, release the path and finish the loop.

Thanks,

Josef

#2 lore raw
In reply to Nikolay Borisov
Quoted 8 lines · Nikolay Borisov

Instead of having 3 'if' to handle non-null return value consolidate this in 1 'if (ret)'. That way the code is more obvious:

- Always drop dlete_unused_bgs_mutex if ret is non null
- If ret is negative -> goto done
- If it's 1 -> reset ret to 0, release the path and finish the loop.

Added to misc-next, thanks.