]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
btrfs: handle unexpected free-space-tree key types
authorDavid Sterba <dsterba@suse.com>
Tue, 14 Apr 2026 15:30:31 +0000 (17:30 +0200)
committerDavid Sterba <dsterba@suse.com>
Tue, 21 Apr 2026 02:02:02 +0000 (04:02 +0200)
Replace the conditional assertions with proper error handling and
transaction abort if we find an unexpected key type in the free space
tree.

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

index 9efd1ec90f031fa038608ba3d232223346f49bd3..472b3060e5ac32ef83eb282ee3aad8e835e28b10 100644 (file)
@@ -259,7 +259,11 @@ int btrfs_convert_free_space_to_bitmaps(struct btrfs_trans_handle *trans,
                                nr++;
                                path->slots[0]--;
                        } else {
-                               ASSERT(0);
+                               btrfs_err(fs_info, "unexpected free space tree key type %u",
+                                         found_key.type);
+                               ret = -EUCLEAN;
+                               btrfs_abort_transaction(trans, ret);
+                               goto out;
                        }
                }
 
@@ -405,7 +409,11 @@ int btrfs_convert_free_space_to_extents(struct btrfs_trans_handle *trans,
 
                                nr++;
                        } else {
-                               ASSERT(0);
+                               btrfs_err(fs_info, "unexpected free space tree key type %u",
+                                         found_key.type);
+                               ret = -EUCLEAN;
+                               btrfs_abort_transaction(trans, ret);
+                               goto out;
                        }
                }
 
@@ -1518,7 +1526,11 @@ int btrfs_remove_block_group_free_space(struct btrfs_trans_handle *trans,
                                nr++;
                                path->slots[0]--;
                        } else {
-                               ASSERT(0);
+                               btrfs_err(trans->fs_info, "unexpected free space tree key type %u",
+                                         found_key.type);
+                               ret = -EUCLEAN;
+                               btrfs_abort_transaction(trans, ret);
+                               return ret;
                        }
                }