Message ID | e6fea9cb64a7c98b4f83e2fd75de31a1475fce28.1724755223.git.fdmanana@suse.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | btrfs: fix uninitialized return value from btrfs_reclaim_sweep() | expand |
On Tue, Aug 27, 2024 at 11:41 AM <fdmanana@kernel.org> wrote: > > From: Filipe Manana <fdmanana@suse.com> > > The return variable 'ret' at btrfs_reclaim_sweep() is never assigned if > none of the space infos is reclaimable (for example if periodic reclaim > is disabled, which is the default), so we return an undefined value. > > This can be fixed my making btrfs_reclaim_sweep() not return any value > as well as do_reclaim_sweep() because: > > 1) do_reclaim_sweep() always returns 0, so we can make it return void; > > 2) The only caller of btrfs_reclaim_sweep() (btrfs_reclaim_bgs()) doesn't > care about its return value, and in its context there's nothing to do > about any errors anyway. > > Therefore return the return value from btrfs_reclaim_sweep() and The first "return" should be "remove", I'll amend that when committing the patch to for-next. > do_reclaim_sweep(). > > Signed-off-by: Filipe Manana <fdmanana@suse.com> > --- > fs/btrfs/space-info.c | 17 +++++------------ > fs/btrfs/space-info.h | 2 +- > 2 files changed, 6 insertions(+), 13 deletions(-) > > diff --git a/fs/btrfs/space-info.c b/fs/btrfs/space-info.c > index 68e14fd48638..c691784b4660 100644 > --- a/fs/btrfs/space-info.c > +++ b/fs/btrfs/space-info.c > @@ -1985,8 +1985,8 @@ static bool is_reclaim_urgent(struct btrfs_space_info *space_info) > return unalloc < data_chunk_size; > } > > -static int do_reclaim_sweep(struct btrfs_fs_info *fs_info, > - struct btrfs_space_info *space_info, int raid) > +static void do_reclaim_sweep(struct btrfs_fs_info *fs_info, > + struct btrfs_space_info *space_info, int raid) > { > struct btrfs_block_group *bg; > int thresh_pct; > @@ -2031,7 +2031,6 @@ static int do_reclaim_sweep(struct btrfs_fs_info *fs_info, > } > > up_read(&space_info->groups_sem); > - return 0; > } > > void btrfs_space_info_update_reclaimable(struct btrfs_space_info *space_info, s64 bytes) > @@ -2074,21 +2073,15 @@ bool btrfs_should_periodic_reclaim(struct btrfs_space_info *space_info) > return ret; > } > > -int btrfs_reclaim_sweep(struct btrfs_fs_info *fs_info) > +void btrfs_reclaim_sweep(struct btrfs_fs_info *fs_info) > { > - int ret; > int raid; > struct btrfs_space_info *space_info; > > list_for_each_entry(space_info, &fs_info->space_info, list) { > if (!btrfs_should_periodic_reclaim(space_info)) > continue; > - for (raid = 0; raid < BTRFS_NR_RAID_TYPES; raid++) { > - ret = do_reclaim_sweep(fs_info, space_info, raid); > - if (ret) > - return ret; > - } > + for (raid = 0; raid < BTRFS_NR_RAID_TYPES; raid++) > + do_reclaim_sweep(fs_info, space_info, raid); > } > - > - return ret; > } > diff --git a/fs/btrfs/space-info.h b/fs/btrfs/space-info.h > index 88b44221ce97..5602026c5e14 100644 > --- a/fs/btrfs/space-info.h > +++ b/fs/btrfs/space-info.h > @@ -294,6 +294,6 @@ void btrfs_space_info_update_reclaimable(struct btrfs_space_info *space_info, s6 > void btrfs_set_periodic_reclaim_ready(struct btrfs_space_info *space_info, bool ready); > bool btrfs_should_periodic_reclaim(struct btrfs_space_info *space_info); > int btrfs_calc_reclaim_threshold(struct btrfs_space_info *space_info); > -int btrfs_reclaim_sweep(struct btrfs_fs_info *fs_info); > +void btrfs_reclaim_sweep(struct btrfs_fs_info *fs_info); > > #endif /* BTRFS_SPACE_INFO_H */ > -- > 2.43.0 > >
On Tue, Aug 27, 2024 at 11:41:19AM +0100, fdmanana@kernel.org wrote: > From: Filipe Manana <fdmanana@suse.com> > > The return variable 'ret' at btrfs_reclaim_sweep() is never assigned if > none of the space infos is reclaimable (for example if periodic reclaim > is disabled, which is the default), so we return an undefined value. > > This can be fixed my making btrfs_reclaim_sweep() not return any value > as well as do_reclaim_sweep() because: > > 1) do_reclaim_sweep() always returns 0, so we can make it return void; > > 2) The only caller of btrfs_reclaim_sweep() (btrfs_reclaim_bgs()) doesn't > care about its return value, and in its context there's nothing to do > about any errors anyway. > > Therefore return the return value from btrfs_reclaim_sweep() and > do_reclaim_sweep(). > > Signed-off-by: Filipe Manana <fdmanana@suse.com> Reviewed-by: Josef Bacik <josef@toxicpanda.com> Thanks, Josef
diff --git a/fs/btrfs/space-info.c b/fs/btrfs/space-info.c index 68e14fd48638..c691784b4660 100644 --- a/fs/btrfs/space-info.c +++ b/fs/btrfs/space-info.c @@ -1985,8 +1985,8 @@ static bool is_reclaim_urgent(struct btrfs_space_info *space_info) return unalloc < data_chunk_size; } -static int do_reclaim_sweep(struct btrfs_fs_info *fs_info, - struct btrfs_space_info *space_info, int raid) +static void do_reclaim_sweep(struct btrfs_fs_info *fs_info, + struct btrfs_space_info *space_info, int raid) { struct btrfs_block_group *bg; int thresh_pct; @@ -2031,7 +2031,6 @@ static int do_reclaim_sweep(struct btrfs_fs_info *fs_info, } up_read(&space_info->groups_sem); - return 0; } void btrfs_space_info_update_reclaimable(struct btrfs_space_info *space_info, s64 bytes) @@ -2074,21 +2073,15 @@ bool btrfs_should_periodic_reclaim(struct btrfs_space_info *space_info) return ret; } -int btrfs_reclaim_sweep(struct btrfs_fs_info *fs_info) +void btrfs_reclaim_sweep(struct btrfs_fs_info *fs_info) { - int ret; int raid; struct btrfs_space_info *space_info; list_for_each_entry(space_info, &fs_info->space_info, list) { if (!btrfs_should_periodic_reclaim(space_info)) continue; - for (raid = 0; raid < BTRFS_NR_RAID_TYPES; raid++) { - ret = do_reclaim_sweep(fs_info, space_info, raid); - if (ret) - return ret; - } + for (raid = 0; raid < BTRFS_NR_RAID_TYPES; raid++) + do_reclaim_sweep(fs_info, space_info, raid); } - - return ret; } diff --git a/fs/btrfs/space-info.h b/fs/btrfs/space-info.h index 88b44221ce97..5602026c5e14 100644 --- a/fs/btrfs/space-info.h +++ b/fs/btrfs/space-info.h @@ -294,6 +294,6 @@ void btrfs_space_info_update_reclaimable(struct btrfs_space_info *space_info, s6 void btrfs_set_periodic_reclaim_ready(struct btrfs_space_info *space_info, bool ready); bool btrfs_should_periodic_reclaim(struct btrfs_space_info *space_info); int btrfs_calc_reclaim_threshold(struct btrfs_space_info *space_info); -int btrfs_reclaim_sweep(struct btrfs_fs_info *fs_info); +void btrfs_reclaim_sweep(struct btrfs_fs_info *fs_info); #endif /* BTRFS_SPACE_INFO_H */