On Tue, Mar 23, 2021 at 03:31:19PM +0100, Arnd Bergmann wrote:
> From: Arnd Bergmann <a...@arndb.de>
> 
> gcc complains that the ctl->max_chunk_size member might be used
> uninitialized when none of the three conditions for initializing it in
> init_alloc_chunk_ctl_policy_zoned() are true:
> 
> In function ‘init_alloc_chunk_ctl_policy_zoned’,
>     inlined from ‘init_alloc_chunk_ctl’ at fs/btrfs/volumes.c:5023:3,
>     inlined from ‘btrfs_alloc_chunk’ at fs/btrfs/volumes.c:5340:2:
> include/linux/compiler-gcc.h:48:45: error: ‘ctl.max_chunk_size’ may be used 
> uninitialized [-Werror=maybe-uninitialized]
>  4998 |         ctl->max_chunk_size = min(limit, ctl->max_chunk_size);
>       |                               ^~~
> fs/btrfs/volumes.c: In function ‘btrfs_alloc_chunk’:
> fs/btrfs/volumes.c:5316:32: note: ‘ctl’ declared here
>  5316 |         struct alloc_chunk_ctl ctl;
>       |                                ^~~
> 
> If we ever get into this condition, something is seriously
> wrong, so the same logic as in init_alloc_chunk_ctl_policy_regular()
> and a few other places should be applied. This avoids both further
> data corruption, and the compile-time warning.
> 
> Fixes: 1cd6121f2a38 ("btrfs: zoned: implement zoned chunk allocator")
> Link: https://lore.kernel.org/lkml/20210323132343.gf7...@twin.jikos.cz/
> Suggested-by: David Sterba <dste...@suse.cz>
> Signed-off-by: Arnd Bergmann <a...@arndb.de>

Added to misc-next, thanks.

Reply via email to