btrfs: add missing error return to btrfs_clear_extent_bit_changeset()
authorFilipe Manana <fdmanana@suse.com>
Thu, 10 Apr 2025 11:59:05 +0000 (12:59 +0100)
committerDavid Sterba <dsterba@suse.com>
Thu, 15 May 2025 12:30:50 +0000 (14:30 +0200)
We have a couple error branches where we have an error stored in the 'err'
variable and then jump to the 'out' label, however we don't return that
error, we just return 0. Normally this is not a problem since those error
branches call extent_io_tree_panic() which triggers a BUG() call, however
it's possible to have rather exotic kernel config with CONFIG_BUG disabled
in which case the BUG() call does nothing and we fallthrough. So make sure
to return the error, not just to fix that exotic case but also to make the
code less confusing. While at it also rename the 'err' variable to 'ret'
since this is the style we prefer and use more widely.

Signed-off-by: Filipe Manana <fdmanana@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/extent-io-tree.c

index b868313e777eb95014997cb7cd5d49661100cc05..3743ff777ada5e4d3c1827781d67cbe3015d62fc 100644 (file)
@@ -604,7 +604,7 @@ int btrfs_clear_extent_bit_changeset(struct extent_io_tree *tree, u64 start, u64
        struct extent_state *cached;
        struct extent_state *prealloc = NULL;
        u64 last_end;
-       int err;
+       int ret = 0;
        int clear = 0;
        int wake;
        int delete = (bits & EXTENT_CLEAR_ALL_BITS);
@@ -690,10 +690,10 @@ hit_next:
                prealloc = alloc_extent_state_atomic(prealloc);
                if (!prealloc)
                        goto search_again;
-               err = split_state(tree, state, prealloc, start);
+               ret = split_state(tree, state, prealloc, start);
                prealloc = NULL;
-               if (err) {
-                       extent_io_tree_panic(tree, state, "split", err);
+               if (ret) {
+                       extent_io_tree_panic(tree, state, "split", ret);
                        goto out;
                }
                if (state->end <= end) {
@@ -711,9 +711,9 @@ hit_next:
                prealloc = alloc_extent_state_atomic(prealloc);
                if (!prealloc)
                        goto search_again;
-               err = split_state(tree, state, prealloc, end + 1);
-               if (err) {
-                       extent_io_tree_panic(tree, state, "split", err);
+               ret = split_state(tree, state, prealloc, end + 1);
+               if (ret) {
+                       extent_io_tree_panic(tree, state, "split", ret);
                        prealloc = NULL;
                        goto out;
                }
@@ -748,7 +748,7 @@ out:
        if (prealloc)
                btrfs_free_extent_state(prealloc);
 
-       return 0;
+       return ret;
 
 }