]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
btrfs: check return value of btrfs_partially_delete_raid_extent()
authorrobbieko <robbieko@synology.com>
Mon, 13 Apr 2026 06:52:37 +0000 (14:52 +0800)
committerDavid Sterba <dsterba@suse.com>
Tue, 21 Apr 2026 02:02:39 +0000 (04:02 +0200)
btrfs_partially_delete_raid_extent() returns an error code (e.g.
-ENOMEM from kzalloc(), or errors from btrfs_del_item/btrfs_insert_item()),
but all three call sites in btrfs_delete_raid_extent() discard the
return value, silently losing errors and potentially leaving the stripe
tree in an inconsistent state.

Fix by capturing the return value into ret at all three call sites and
breaking out of the loop on error where appropriate.

Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: robbieko <robbieko@synology.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/raid-stripe-tree.c

index 2e0d2f83c6516f38cd1fd4ac1cc18e0c26fc07ce..4b0186c83ad1d8857c673455d0207d695adeeb38 100644 (file)
@@ -223,8 +223,9 @@ int btrfs_delete_raid_extent(struct btrfs_trans_handle *trans, u64 start, u64 le
                        /* The "left" item. */
                        path->slots[0]--;
                        btrfs_item_key_to_cpu(leaf, &key, path->slots[0]);
-                       btrfs_partially_delete_raid_extent(trans, path, &key,
-                                                          diff_start, 0);
+                       ret = btrfs_partially_delete_raid_extent(trans, path,
+                                                                &key,
+                                                                diff_start, 0);
                        break;
                }
 
@@ -240,8 +241,11 @@ int btrfs_delete_raid_extent(struct btrfs_trans_handle *trans, u64 start, u64 le
                if (found_start < start) {
                        u64 diff_start = start - found_start;
 
-                       btrfs_partially_delete_raid_extent(trans, path, &key,
-                                                          diff_start, 0);
+                       ret = btrfs_partially_delete_raid_extent(trans, path,
+                                                                &key,
+                                                                diff_start, 0);
+                       if (ret)
+                               break;
 
                        start += (key.offset - diff_start);
                        length -= (key.offset - diff_start);
@@ -264,9 +268,10 @@ int btrfs_delete_raid_extent(struct btrfs_trans_handle *trans, u64 start, u64 le
                if (found_end > end) {
                        u64 diff_end = found_end - end;
 
-                       btrfs_partially_delete_raid_extent(trans, path, &key,
-                                                          key.offset - length,
-                                                          length);
+                       ret = btrfs_partially_delete_raid_extent(trans, path,
+                                                                &key,
+                                                                key.offset - length,
+                                                                length);
                        ASSERT(key.offset - diff_end == length);
                        break;
                }