diff mbox series

btrfs: Consolidate btrfs_previous_item ret val handling in btrfs_shrink_device

Message ID 20201217132116.328291-1-nborisov@suse.com (mailing list archive)
State New, archived
Headers show
Series btrfs: Consolidate btrfs_previous_item ret val handling in btrfs_shrink_device | expand

Commit Message

Nikolay Borisov Dec. 17, 2020, 1:21 p.m. UTC
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.

Signed-off-by: Nikolay Borisov <nborisov@suse.com>
---
 fs/btrfs/volumes.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

Comments

Josef Bacik Dec. 17, 2020, 2:44 p.m. UTC | #1
On 12/17/20 8:21 AM, Nikolay Borisov wrote:
> 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.
> 
> Signed-off-by: Nikolay Borisov <nborisov@suse.com>

Reviewed-by: Josef Bacik <josef@toxicpanda.com>

Thanks,

Josef
David Sterba Dec. 21, 2020, 5:02 p.m. UTC | #2
On Thu, Dec 17, 2020 at 03:21:16PM +0200, Nikolay Borisov wrote:
> 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.
> 
> Signed-off-by: Nikolay Borisov <nborisov@suse.com>

Added to misc-next, thanks.
diff mbox series

Patch

diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 7930e1c78c45..a34eded1bfbe 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -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;