btrfs: fix a resource leak in btrfs_init_sysfs()
PATCH 1/1 btrfs: fix a resource leak in btrfs_init_sysfs()
When btrfs_debug_feature_attr_group fails to be created, btrfs_feature_attr_group is not removed.
--- fs/btrfs/sysfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/sysfs.c +1 -1
@@ -2322,7 +2322,7 @@ 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; + goto out_remove_group;#endif return 0 ;
Signature · 1 line
2.25.1
Quoted 4 lines · Zhen Lei
When
btrfs_debug_feature_attr_groupfails to be created,btrfs_feature_attr_groupis not removed.Signed-off-by Zhen Lei <[email protected]>
Thanks,
Qu
Quoted 17 lines
--- fs/btrfs/sysfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)fs/btrfs/sysfs.c +1
-1@@ -2322,7 +2322,7 @@ 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; + goto out_remove_group;#endif return 0 ;
Quoted 9 lines · Qu Wenruo
Quoted 4 lines · Zhen Lei
When
btrfs_debug_feature_attr_groupfails to be created,btrfs_feature_attr_groupis not removed.Signed-off-by Zhen Lei <[email protected]>Reviewed-by Qu Wenruo <[email protected]>
Wait for a minute, should we call sysfs_unmerge_group() first before calling sysfs_remove_group()?
As the sysfs_remove_group() will only remove the btrfs_feature_attr_group, and kset_unregister() will only free btrfs_kset, without removing the added btrfs_static_feature_attr_group.
I haven't yet find a function that will remove all children attrs in just one go, or did I miss something?
Thanks,
Qu
Quoted 19 lines
Thanks,
QuQuoted 16 lines
---
fs/btrfs/sysfs.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)fs/btrfs/sysfs.c +1
-1@@ -2322,7 +2322,7 @@ 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; + goto out_remove_group; #endif return 0;
Quoted 11 lines · Qu Wenruo
Quoted 8 lines · Qu Wenruo
Quoted 4 lines · Zhen Lei
When
btrfs_debug_feature_attr_groupfails to be created,btrfs_feature_attr_groupis not removed.Signed-off-by Zhen Lei <[email protected]>
Quoted 7 lines
Quoted 1 line
Reviewed-by Qu Wenruo <[email protected]>Wait for a minute, should we call
sysfs_unmerge_group()first before callingsysfs_remove_group()?As the
sysfs_remove_group()will only remove thebtrfs_feature_attr_group, andkset_unregister()will only freebtrfs_kset, without removing the addedbtrfs_static_feature_attr_group.I haven't yet find a function that will remove all children attrs in just one go, or did I miss something?
Oh, indeed I missed something.
The following call chain would properly handle every child of a kobj:
kset_unregister()
|- kobject_del()
|- __kobject_del()
|- sysfs_remove_dir()
|- kernfs_remove()
|- __kernfs_remove()
|- do { kernfs_leftmost_descendant(); } while (pos != kn)The final do {} while () loop will unlink each child kernel_node and free it.
This means, as long as we call kset_unregister(), we should be able to free every child of it.
So with or without this patch, the error handling should be fine.
Although personally speaking, I'd prefer a more explicit cleanup (with extra sysfs_unmerge_group() call) as going through the above call chain is not that straightforward.
Thanks,
Qu
Quoted 22 lines
Thanks,
QuQuoted 19 lines
Thanks,
QuQuoted 16 lines
---
fs/btrfs/sysfs.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)fs/btrfs/sysfs.c +1
-1@@ -2322,7 +2322,7 @@ 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; + goto out_remove_group; #endif return 0;
Quoted 34 lines · Qu Wenruo
Quoted 11 lines · Qu Wenruo
Quoted 8 lines · Qu Wenruo
Quoted 4 lines · Zhen Lei
When
btrfs_debug_feature_attr_groupfails to be created,btrfs_feature_attr_groupis not removed.Signed-off-by Zhen Lei <[email protected]>Quoted 7 lines
Quoted 1 line
Reviewed-by Qu Wenruo <[email protected]>Wait for a minute, should we call
sysfs_unmerge_group()first before callingsysfs_remove_group()?As the
sysfs_remove_group()will only remove thebtrfs_feature_attr_group, andkset_unregister()will only freebtrfs_kset, without removing the addedbtrfs_static_feature_attr_group.I haven't yet find a function that will remove all children attrs in just one go, or did I miss something?
Oh, indeed I missed something.
The following call chain would properly handle every child of a kobj:
kset_unregister()
|-kobject_del()
|-__kobject_del()
|-sysfs_remove_dir()
|-kernfs_remove()
|-__kernfs_remove()
|- do {kernfs_leftmost_descendant(); } while (pos != kn)
Quoted 3 lines
The final do {} while () loop will unlink each child
kernel_nodeand free it.This means, as long as we call
kset_unregister(), we should be able to free every child of it.
OK, thanks.
Quoted 5 lines
So with or without this patch, the error handling should be fine.
Although personally speaking, I'd prefer a more explicit cleanup (with extra
sysfs_unmerge_group()call) as going through the above call chain is not that straightforward.
Yes, with sysfs_unmerge_group(), the code logic is clearer.
Quoted 28 lines
Thanks,
QuQuoted 10 lines
Thanks,
QuQuoted 7 lines
Thanks,
QuQuoted 4 lines
---
fs/btrfs/sysfs.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)Quoted 12 lines
Quoted 4 lines
Quoted 4 lines
fs/btrfs/sysfs.c +0
-0Quoted 8 lines
fs/btrfs/sysfs.c int __init btrfs_init_sysfs(void) · line 2327
Quoted 8 lines
fs/btrfs/sysfs.c +1
-1@@ -2322,7 +2322,7 @@ 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; + goto out_remove_group; #endif return 0;.
Signature · 2 lines
Regards, Zhen Lei