Re: [PATCH v2] btrfs: fix zoned sub_group leak on space_info sysfs failure

From: Johannes Thumshirn

Date: Tue Jun 09 2026 - 13:13:43 EST


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.