Skip to content

Commit 6927a91

Browse files
adam900710gregkh
authored andcommitted
btrfs: make found_logical_ret parameter mandatory for function queue_scrub_stripe()
[ Upstream commit 47e2b06 ] [BUG] There is a compilation warning reported on commit ae76d8e ("btrfs: scrub: fix grouping of read IO"), where gcc (14.0.0 20231022 experimental) is reporting the following uninitialized variable: fs/btrfs/scrub.c: In function ‘scrub_simple_mirror.isra’: fs/btrfs/scrub.c:2075:29: error: ‘found_logical’ may be used uninitialized [-Werror=maybe-uninitialized[https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wmaybe-uninitialized]] 2075 | cur_logical = found_logical + BTRFS_STRIPE_LEN; fs/btrfs/scrub.c:2040:21: note: ‘found_logical’ was declared here 2040 | u64 found_logical; | ^~~~~~~~~~~~~ [CAUSE] This is a false alert, as @found_logical is passed as parameter @found_logical_ret of function queue_scrub_stripe(). As long as queue_scrub_stripe() returned 0, we would update @found_logical_ret. And if queue_scrub_stripe() returned >0 or <0, the caller would not utilized @found_logical, thus there should be nothing wrong. Although the triggering gcc is still experimental, it looks like the extra check on "if (found_logical_ret)" can sometimes confuse the compiler. Meanwhile the only caller of queue_scrub_stripe() is always passing a valid pointer, there is no need for such check at all. [FIX] Although the report itself is a false alert, we can still make it more explicit by: - Replace the check for @found_logical_ret with ASSERT() - Initialize @found_logical to U64_MAX - Add one extra ASSERT() to make sure @found_logical got updated Link: https://lore.kernel.org/linux-btrfs/[email protected]/ Fixes: ae76d8e ("btrfs: scrub: fix grouping of read IO") Reviewed-by: Anand Jain <[email protected]> Signed-off-by: Qu Wenruo <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent 9ac639d commit 6927a91

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

fs/btrfs/scrub.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1798,6 +1798,9 @@ static int queue_scrub_stripe(struct scrub_ctx *sctx, struct btrfs_block_group *
17981798
*/
17991799
ASSERT(sctx->cur_stripe < SCRUB_TOTAL_STRIPES);
18001800

1801+
/* @found_logical_ret must be specified. */
1802+
ASSERT(found_logical_ret);
1803+
18011804
stripe = &sctx->stripes[sctx->cur_stripe];
18021805
scrub_reset_stripe(stripe);
18031806
ret = scrub_find_fill_first_stripe(bg, &sctx->extent_path,
@@ -1806,8 +1809,7 @@ static int queue_scrub_stripe(struct scrub_ctx *sctx, struct btrfs_block_group *
18061809
/* Either >0 as no more extents or <0 for error. */
18071810
if (ret)
18081811
return ret;
1809-
if (found_logical_ret)
1810-
*found_logical_ret = stripe->logical;
1812+
*found_logical_ret = stripe->logical;
18111813
sctx->cur_stripe++;
18121814

18131815
/* We filled one group, submit it. */
@@ -2010,7 +2012,7 @@ static int scrub_simple_mirror(struct scrub_ctx *sctx,
20102012

20112013
/* Go through each extent items inside the logical range */
20122014
while (cur_logical < logical_end) {
2013-
u64 found_logical;
2015+
u64 found_logical = U64_MAX;
20142016
u64 cur_physical = physical + cur_logical - logical_start;
20152017

20162018
/* Canceled? */
@@ -2045,6 +2047,8 @@ static int scrub_simple_mirror(struct scrub_ctx *sctx,
20452047
if (ret < 0)
20462048
break;
20472049

2050+
/* queue_scrub_stripe() returned 0, @found_logical must be updated. */
2051+
ASSERT(found_logical != U64_MAX);
20482052
cur_logical = found_logical + BTRFS_STRIPE_LEN;
20492053

20502054
/* Don't hold CPU for too long time */

0 commit comments

Comments
 (0)