]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
btrfs: make add_extent_changeset() only return errors or success
authorFilipe Manana <fdmanana@suse.com>
Wed, 11 Mar 2026 12:17:03 +0000 (12:17 +0000)
committerDavid Sterba <dsterba@suse.com>
Tue, 7 Apr 2026 16:56:03 +0000 (18:56 +0200)
Currently add_extent_changeset() always returns the return value from its
call to ulist_add(), which can return an error, 0 or 1. There are no
callers that care about the difference between 0 and 1 and all except one
of them, check for negative values and ignore other values, but there is
another caller (btrfs_clear_extent_bit_changeset()) that must set its
'ret' variable to 0 after calling add_extent_changeset(), so that it
does not return an unexpected value of 1 to its caller.

So change add_extent_changeset() to only return errors or 0, avoiding
that caller (and any future callers) from having to deal with a return
value of 1.

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 93dca919924960d3269149fae0822ab8467f0c15..5972fe28716e4af93d6b2608f9ed29bb7a10edf0 100644 (file)
@@ -187,6 +187,8 @@ static int add_extent_changeset(struct extent_state *state, u32 bits,
                                 struct extent_changeset *changeset,
                                 int set)
 {
+       int ret;
+
        if (!changeset)
                return 0;
        if (set && (state->state & bits) == bits)
@@ -195,7 +197,10 @@ static int add_extent_changeset(struct extent_state *state, u32 bits,
                return 0;
        changeset->bytes_changed += state->end - state->start + 1;
 
-       return ulist_add(&changeset->range_changed, state->start, state->end, GFP_ATOMIC);
+       ret = ulist_add(&changeset->range_changed, state->start, state->end, GFP_ATOMIC);
+       if (ret < 0)
+               return ret;
+       return 0;
 }
 
 static inline struct extent_state *next_state(struct extent_state *state)
@@ -745,7 +750,6 @@ hit_next:
                                                     "add_extent_changeset", ret);
                                goto out;
                        }
-                       ret = 0;
 
                        if (tree->owner == IO_TREE_INODE_IO)
                                btrfs_clear_delalloc_extent(tree->inode, state, bits);