Skip to content

Commit 20218df

Browse files
josefbacikkdave
authored andcommitted
btrfs: make sure to initialize start and len in find_free_dev_extent
Jens reported a compiler error when using CONFIG_CC_OPTIMIZE_FOR_SIZE=y that looks like this In function ‘gather_device_info’, inlined from ‘btrfs_create_chunk’ at fs/btrfs/volumes.c:5507:8: fs/btrfs/volumes.c:5245:48: warning: ‘dev_offset’ may be used uninitialized [-Wmaybe-uninitialized] 5245 | devices_info[ndevs].dev_offset = dev_offset; | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~ fs/btrfs/volumes.c: In function ‘btrfs_create_chunk’: fs/btrfs/volumes.c:5196:13: note: ‘dev_offset’ was declared here 5196 | u64 dev_offset; This occurs because find_free_dev_extent is responsible for setting dev_offset, however if we get an -ENOMEM at the top of the function we'll return without setting the value. This isn't actually a problem because we will see the -ENOMEM in gather_device_info() and return and not use the uninitialized value, however we also just don't want the compiler warning so rework the code slightly in find_free_dev_extent() to make sure it's always setting *start and *len to avoid the compiler warning. Reported-by: Jens Axboe <[email protected]> Tested-by: Jens Axboe <[email protected]> Reviewed-by: Qu Wenruo <[email protected]> Signed-off-by: Josef Bacik <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 74ee791 commit 20218df

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

fs/btrfs/volumes.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1594,25 +1594,24 @@ static int find_free_dev_extent(struct btrfs_device *device, u64 num_bytes,
15941594
u64 search_start;
15951595
u64 hole_size;
15961596
u64 max_hole_start;
1597-
u64 max_hole_size;
1597+
u64 max_hole_size = 0;
15981598
u64 extent_end;
15991599
u64 search_end = device->total_bytes;
16001600
int ret;
16011601
int slot;
16021602
struct extent_buffer *l;
16031603

16041604
search_start = dev_extent_search_start(device);
1605+
max_hole_start = search_start;
16051606

16061607
WARN_ON(device->zone_info &&
16071608
!IS_ALIGNED(num_bytes, device->zone_info->zone_size));
16081609

16091610
path = btrfs_alloc_path();
1610-
if (!path)
1611-
return -ENOMEM;
1612-
1613-
max_hole_start = search_start;
1614-
max_hole_size = 0;
1615-
1611+
if (!path) {
1612+
ret = -ENOMEM;
1613+
goto out;
1614+
}
16161615
again:
16171616
if (search_start >= search_end ||
16181617
test_bit(BTRFS_DEV_STATE_REPLACE_TGT, &device->dev_state)) {

0 commit comments

Comments
 (0)