Skip to contentSkip to conversation

btrfs: normalize the error handling branch in btrfs_init_sysfs()

PATCH In review Zhen Lei 3 participants 3 messages Nov 22, 2022 Btrfs file system

lore
Share & tools
lore

Zhen Lei

author
#0 lore raw

PATCH v2 1/1 btrfs: normalize the error handling branch in btrfs_init_sysfs()

Although kset_unregister() can eventually remove all attribute files, explicitly rolling back with the matching function makes the code logic look clearer.

---
 fs/btrfs/sysfs.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

v1 --> v2:
1. Add sysfs_unmerge_group() to unmerge group first.
2. Update subject and commit message, no resource leaks.

fs/btrfs/sysfs.c +5 -2
index 699b54b3acaae0b..74fef1f49c358cd 100644
@@ -2321,8 +2321,11 @@ int __init btrfs_init_sysfs(void)
 
 #ifdef CONFIG_BTRFS_DEBUG
 	ret = sysfs_create_group(&btrfs_kset->kobj, &btrfs_debug_feature_attr_group);
-	if (ret)
-		goto out2;
+	if (ret) {
+		sysfs_unmerge_group(&btrfs_kset->kobj,
+				    &btrfs_static_feature_attr_group);
+		goto out_remove_group;
+	}
 #endif
 
 	return 0;
Signature · 1 line
2.25.1
Reviewed-by on v2 1/1
#1 lore raw
Quoted 5 lines · Zhen Lei

Although kset_unregister() can eventually remove all attribute files, explicitly rolling back with the matching function makes the code logic look clearer.

Thanks,
Qu

Quoted 26 lines
---
  fs/btrfs/sysfs.c | 7 +++++--
  1 file changed, 5 insertions(+), 2 deletions(-)

v1 --> v2:
1. Add sysfs_unmerge_group() to unmerge group first.
2. Update subject and commit message, no resource leaks.

fs/btrfs/sysfs.c +5 -2
index 699b54b3acaae0b..74fef1f49c358cd 100644
@@ -2321,8 +2321,11 @@ int __init btrfs_init_sysfs(void)
 
  #ifdef CONFIG_BTRFS_DEBUG
  	ret = sysfs_create_group(&btrfs_kset->kobj, &btrfs_debug_feature_attr_group);
-	if (ret)
-		goto out2;
+	if (ret) {
+		sysfs_unmerge_group(&btrfs_kset->kobj,
+				    &btrfs_static_feature_attr_group);
+		goto out_remove_group;
+	}
  #endif
 
  	return 0;