Re: [PATCH v2] btrfs: fix zoned sub_group leak on space_info sysfs failure
From: Guangshuo Li
Date: Wed Jun 10 2026 - 02:43:33 EST
Hi Johannes,
Thank you for the review.
On Wed, 10 Jun 2026 at 01:04, Johannes Thumshirn
<johannes.thumshirn@xxxxxxx> wrote:
>
> On 6/9/26 5:20 PM, Guangshuo Li wrote:
> > diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
> > index 0d14570c8bc2..ce1109e47cc7 100644
> > --- a/fs/btrfs/sysfs.c
> > +++ b/fs/btrfs/sysfs.c
> > @@ -1885,6 +1885,22 @@ void btrfs_sysfs_remove_space_info(struct btrfs_space_info *space_info)
> > {
> > int i;
> >
> > + for (i = 0; i < ARRAY_SIZE(space_info->sub_group); i++) {
> > + struct btrfs_space_info *sub_group;
> > +
> > + sub_group = space_info->sub_group[i];
> > + if (!sub_group)
> > + continue;
>
> I think you can break here instead of continue. space_info->sub_group is
> not expected to have holes.
>
>
> > +
> > + /*
> > + * Remove sub-groups before removing their parent space_info.
> > + * Clear the pointer first so recursive removal cannot leave a
> > + * stale child pointer behind.
> > + */
> > + space_info->sub_group[i] = NULL;
> > + btrfs_sysfs_remove_space_info(sub_group);
>
> That comment IMHO doesn't add any value.
>
>
>
I agree, sub_group[] is not expected to have holes, so using break here
is better than continue. I will also drop the comment as suggested.
I will send a v3 with these changes.
Thanks,
Guangshuo