]> Git Repo - linux.git/commit - fs/btrfs/volumes.c
btrfs: make sure to initialize start and len in find_free_dev_extent
authorJosef Bacik <[email protected]>
Tue, 5 Sep 2023 16:15:23 +0000 (12:15 -0400)
committerDavid Sterba <[email protected]>
Thu, 21 Sep 2023 16:52:20 +0000 (18:52 +0200)
commit20218dfbaa31b8d3ef842fafcc7eb4c6aa03f80a
tree3e6af844981424f93aad1f799e7b053d46926e3d
parent74ee79142c0a344d4eae2eb7012ebc4e82254109
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]>
fs/btrfs/volumes.c
This page took 0.052569 seconds and 4 git commands to generate.