Skip to content

Commit 9da45c8

Browse files
fdmananakdave
authored andcommitted
btrfs: fix uninitialized return value in the ref-verify tool
In the ref-verify tool, when processing the inline references of an extent item, we may end up returning with uninitialized return value, because: 1) The 'ret' variable is not initialized if there are no inline extent references ('ptr' == 'end' before the while loop starts); 2) If we find an extent owner inline reference we don't initialize 'ret'. So fix these cases by initializing 'ret' to 0 when declaring the variable and set it to -EINVAL if we find an extent owner inline references and simple quotas are not enabled (as well as print an error message). Reported-by: Mirsad Todorovac <[email protected]> Link: https://lore.kernel.org/linux-btrfs/[email protected]/ Signed-off-by: Filipe Manana <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 724d804 commit 9da45c8

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

fs/btrfs/ref-verify.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,8 @@ static int process_extent_item(struct btrfs_fs_info *fs_info,
441441
u32 item_size = btrfs_item_size(leaf, slot);
442442
unsigned long end, ptr;
443443
u64 offset, flags, count;
444-
int type, ret;
444+
int type;
445+
int ret = 0;
445446

446447
ei = btrfs_item_ptr(leaf, slot, struct btrfs_extent_item);
447448
flags = btrfs_extent_flags(leaf, ei);
@@ -486,7 +487,11 @@ static int process_extent_item(struct btrfs_fs_info *fs_info,
486487
key->objectid, key->offset);
487488
break;
488489
case BTRFS_EXTENT_OWNER_REF_KEY:
489-
WARN_ON(!btrfs_fs_incompat(fs_info, SIMPLE_QUOTA));
490+
if (!btrfs_fs_incompat(fs_info, SIMPLE_QUOTA)) {
491+
btrfs_err(fs_info,
492+
"found extent owner ref without simple quotas enabled");
493+
ret = -EINVAL;
494+
}
490495
break;
491496
default:
492497
btrfs_err(fs_info, "invalid key type in iref");

0 commit comments

Comments
 (0)