btrfs: initialize offset early
Subsystems (2)
PATCH 1/1 btrfs: initialize offset early
Jump to out label can happen before offset is initialized. offset is being used in code after out label. initialize offset early to cater this case.
--- fs/btrfs/scrub.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
fs/btrfs/scrub.c +1 -2
@@ -3530,7 +3530,7 @@ static noinline_for_stack int scrub_stripe(struct scrub_ctx *sctx,u64 logic_end;u64 physical_end;u64 increment;/* The logical increment after finishing one stripe */ -u64 offset;/* Offset inside the chunk */ +u64 offset =0 ;/* Offset inside the chunk */ u64 stripe_logical;u64 stripe_end;
@@ -3602,7 +3602,6 @@ static noinline_for_stack int scrub_stripe(struct scrub_ctx *sctx,ASSERT (map->type &BTRFS_BLOCK_GROUP_RAID56_MASK ); physical = map->stripes[stripe_index].physical; - offset =0 ; nstripes =div64_u64 (dev_extent_len, map->stripe_len);get_raid56_logic_offset (physical, stripe_index, map, &offset,NULL ); increment = map->stripe_len *nr_data_stripes (map);
Signature · 1 line
2.30.2
Quoted 6 lines · Muhammad Usama Anjum
Jump to out label can happen before offset is initialized. offset is being used in code after out label. initialize offset early to cater this case.
Fixes 585f784357d8 ("btrfs: use scrub_simple_mirror() to handle RAID56 data stripe scrub")Signed-off-by Muhammad Usama Anjum <[email protected]>
Thanks for the fix.
Although the patch is only in misc-next, and due to another triggered ASSERT(), the series will be reworked soon.
Thanks,
Qu
Quoted 25 lines
--- fs/btrfs/scrub.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)fs/btrfs/scrub.c +1
-2@@ -3530,7 +3530,7 @@ static noinline_for_stack int scrub_stripe(struct scrub_ctx *sctx,u64 logic_end;u64 physical_end;u64 increment;/* The logical increment after finishing one stripe */ -u64 offset;/* Offset inside the chunk */ +u64 offset =0 ;/* Offset inside the chunk */ u64 stripe_logical;u64 stripe_end;@@ -3602,7 +3602,6 @@ static noinline_for_stack int scrub_stripe(struct scrub_ctx *sctx,ASSERT (map->type &BTRFS_BLOCK_GROUP_RAID56_MASK ); physical = map->stripes[stripe_index].physical; - offset =0 ; nstripes =div64_u64 (dev_extent_len, map->stripe_len);get_raid56_logic_offset (physical, stripe_index, map, &offset,NULL ); increment = map->stripe_len *nr_data_stripes (map);
Quoted 15 lines · Muhammad Usama Anjum
Jump to out label can happen before offset is initialized. offset is being used in code after out label. initialize offset early to cater this case.
Fixes 585f784357d8 ("btrfs: use scrub_simple_mirror() to handle RAID56 data stripe scrub")Signed-off-by Muhammad Usama Anjum <[email protected]>--- fs/btrfs/scrub.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)fs/btrfs/scrub.c +0
-0
fs/btrfs/scrub.c static noinline_for_stack int scrub_stripe(struct scrub_ctx *sctx, · line 3531
Quoted 2 lines
fs/btrfs/scrub.c +0
-0@@ -3530,7 +3530,7 @@ static noinline_for_stack int scrub_stripe(struct scrub_ctx *sctx,u64 logic_end;u64 physical_end;
^^^^^^^^^^^^
fs/btrfs/scrub.c static noinline_for_stack int scrub_stripe(struct scrub_ctx *sctx, · line 3536
Quoted 6 lines
fs/btrfs/scrub.c +1
-1u64 increment;/* The logical increment after finishing one stripe */ -u64 offset;/* Offset inside the chunk */ +u64 offset =0 ;/* Offset inside the chunk */ u64 stripe_logical;u64 stripe_end;
The same checker which complained about offset also complained about physical_end. Please don't post random half patches which aren't going to fix the crash.
If you don't know how to fix it, then just report it to the original author. This one was already reported. (I think. Anyway, consider it reported now.)
regards,
dan carpenter