]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
btrfs: handle discard errors in in btrfs_finish_extent_commit()
authorJingkai Tan <contact@jingk.ai>
Thu, 22 Jan 2026 21:14:10 +0000 (21:14 +0000)
committerDavid Sterba <dsterba@suse.com>
Thu, 26 Feb 2026 14:03:26 +0000 (15:03 +0100)
Coverity (ID: 1226842) reported that the return value of
btrfs_discard_extent() is assigned to ret but is immediately
overwritten by unpin_extent_range() without being checked.

Use the same error handling that is done later in the same function.

Signed-off-by: Jingkai Tan <contact@jingk.ai>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/extent-tree.c

index 03cf9f242c70021c21563bc251eb756028faa8a7..b0d9baf5b41288242ccee86d5538098712b087f8 100644 (file)
@@ -2933,9 +2933,15 @@ int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans)
        while (!TRANS_ABORTED(trans) && cached_state) {
                struct extent_state *next_state;
 
-               if (btrfs_test_opt(fs_info, DISCARD_SYNC))
+               if (btrfs_test_opt(fs_info, DISCARD_SYNC)) {
                        ret = btrfs_discard_extent(fs_info, start,
                                                   end + 1 - start, NULL, true);
+                       if (ret) {
+                               btrfs_warn(fs_info,
+                               "discard failed for extent [%llu, %llu]: errno=%d %s",
+                                          start, end, ret, btrfs_decode_error(ret));
+                       }
+               }
 
                next_state = btrfs_next_extent_state(unpin, cached_state);
                btrfs_clear_extent_dirty(unpin, start, end, &cached_state);