]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
btrfs: move min sys chunk array size check to validate_sys_chunk_array()
authorFilipe Manana <fdmanana@suse.com>
Tue, 3 Feb 2026 15:22:54 +0000 (15:22 +0000)
committerDavid Sterba <dsterba@suse.com>
Tue, 7 Apr 2026 16:55:52 +0000 (18:55 +0200)
We check the minimum size of the sys chunk array in btrfs_validate_super()
but we have a better place for that, the helper validate_sys_chunk_array()
which we use for every other sys chunk array check. So move it there, also
converting the return error from -EINVAL to -EUCLEAN, which is a better
fit and also consistent with the other checks.

Reviewed-by: Qu Wenruo <wqu@suse.com>
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/disk-io.c

index 1b5fa0681331120da48d737b67ffdd4f972a5015..6c4a791838de28a543b71100e05d61e12d010de3 100644 (file)
@@ -2299,6 +2299,15 @@ static int validate_sys_chunk_array(const struct btrfs_fs_info *fs_info,
                return -EUCLEAN;
        }
 
+       /* It must hold at least one key and one chunk. */
+       if (unlikely(sys_array_size < sizeof(struct btrfs_disk_key) +
+                    sizeof(struct btrfs_chunk))) {
+               btrfs_err(fs_info, "system chunk array too small %u < %zu",
+                         sys_array_size,
+                         sizeof(struct btrfs_disk_key) + sizeof(struct btrfs_chunk));
+               return -EUCLEAN;
+       }
+
        while (cur < sys_array_size) {
                struct btrfs_disk_key *disk_key;
                struct btrfs_chunk *chunk;
@@ -2541,19 +2550,6 @@ int btrfs_validate_super(const struct btrfs_fs_info *fs_info,
 
        ret = validate_sys_chunk_array(fs_info, sb);
 
-       /*
-        * Obvious sys_chunk_array corruptions, it must hold at least one key
-        * and one chunk
-        */
-       if (btrfs_super_sys_array_size(sb) < sizeof(struct btrfs_disk_key)
-                       + sizeof(struct btrfs_chunk)) {
-               btrfs_err(fs_info, "system chunk array too small %u < %zu",
-                         btrfs_super_sys_array_size(sb),
-                         sizeof(struct btrfs_disk_key)
-                         + sizeof(struct btrfs_chunk));
-               ret = -EINVAL;
-       }
-
        /*
         * The generation is a global counter, we'll trust it more than the others
         * but it's still possible that it's the one that's wrong.