1 ext4: release kobject/kset even when init/register fail
3 From: Riccardo Schirone <sirmy15@gmail.com>
5 Even when kobject_init_and_add/kset_register fail, the kobject has been
6 already initialized and the refcount set to 1. Thus it is necessary to
7 release the kobject/kset, to avoid the memory associated with it hanging
10 Signed-off-by: Riccardo Schirone <sirmy15@gmail.com>
11 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
13 fs/ext4/sysfs.c | 15 +++++++++++----
14 1 file changed, 11 insertions(+), 4 deletions(-)
16 diff --git a/fs/ext4/sysfs.c b/fs/ext4/sysfs.c
17 index 48c7a7d55ed3..b096e157934f 100644
20 @@ -395,8 +395,11 @@ int ext4_register_sysfs(struct super_block *sb)
21 init_completion(&sbi->s_kobj_unregister);
22 err = kobject_init_and_add(&sbi->s_kobj, &ext4_sb_ktype, NULL,
26 + kobject_put(&sbi->s_kobj);
27 + wait_for_completion(&sbi->s_kobj_unregister);
32 sbi->s_proc = proc_mkdir(sb->s_id, ext4_proc_root);
33 @@ -429,15 +432,19 @@ int __init ext4_init_sysfs(void)
34 kobject_set_name(&ext4_kset.kobj, "ext4");
35 ext4_kset.kobj.parent = fs_kobj;
36 ret = kset_register(&ext4_kset);
39 + kset_unregister(&ext4_kset);
43 ret = kobject_init_and_add(&ext4_feat, &ext4_feat_ktype,
47 + kobject_put(&ext4_feat);
48 kset_unregister(&ext4_kset);
51 ext4_proc_root = proc_mkdir(proc_dirname, NULL);