btrfs: move min sys chunk array size check to validate_sys_chunk_array()

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>
This commit is contained in:
Filipe Manana 2026-02-03 15:22:54 +00:00 committed by David Sterba
parent f3da62571b
commit 6141abb7f1

View 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.