diff options
author | Riccardo Schirone <sirmy15@gmail.com> | 2018-01-11 14:28:13 -0500 |
---|---|---|
committer | Theodore Ts'o <tytso@mit.edu> | 2018-01-11 14:28:13 -0500 |
commit | 95c4df029374d8c09ad36c961e7a14a1d3ac6a6f (patch) | |
tree | f5a9cd8c23ea7328a5babedd0cab8763074305a2 | |
parent | a794df0ecdd557961a0302062f5a7a5f500a8542 (diff) |
ext4: release kobject/kset even when init/register fail
Even when kobject_init_and_add/kset_register fail, the kobject has been
already initialized and the refcount set to 1. Thus it is necessary to
release the kobject/kset, to avoid the memory associated with it hanging
around forever.
Signed-off-by: Riccardo Schirone <sirmy15@gmail.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
-rw-r--r-- | fs/ext4/sysfs.c | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/fs/ext4/sysfs.c b/fs/ext4/sysfs.c index e21afd52e7d7..4389fe4893c2 100644 --- a/fs/ext4/sysfs.c +++ b/fs/ext4/sysfs.c | |||
@@ -396,8 +396,11 @@ int ext4_register_sysfs(struct super_block *sb) | |||
396 | init_completion(&sbi->s_kobj_unregister); | 396 | init_completion(&sbi->s_kobj_unregister); |
397 | err = kobject_init_and_add(&sbi->s_kobj, &ext4_sb_ktype, NULL, | 397 | err = kobject_init_and_add(&sbi->s_kobj, &ext4_sb_ktype, NULL, |
398 | "%s", sb->s_id); | 398 | "%s", sb->s_id); |
399 | if (err) | 399 | if (err) { |
400 | kobject_put(&sbi->s_kobj); | ||
401 | wait_for_completion(&sbi->s_kobj_unregister); | ||
400 | return err; | 402 | return err; |
403 | } | ||
401 | 404 | ||
402 | if (ext4_proc_root) | 405 | if (ext4_proc_root) |
403 | sbi->s_proc = proc_mkdir(sb->s_id, ext4_proc_root); | 406 | sbi->s_proc = proc_mkdir(sb->s_id, ext4_proc_root); |
@@ -430,15 +433,19 @@ int __init ext4_init_sysfs(void) | |||
430 | kobject_set_name(&ext4_kset.kobj, "ext4"); | 433 | kobject_set_name(&ext4_kset.kobj, "ext4"); |
431 | ext4_kset.kobj.parent = fs_kobj; | 434 | ext4_kset.kobj.parent = fs_kobj; |
432 | ret = kset_register(&ext4_kset); | 435 | ret = kset_register(&ext4_kset); |
433 | if (ret) | 436 | if (ret) { |
437 | kset_unregister(&ext4_kset); | ||
434 | return ret; | 438 | return ret; |
439 | } | ||
435 | 440 | ||
436 | ret = kobject_init_and_add(&ext4_feat, &ext4_feat_ktype, | 441 | ret = kobject_init_and_add(&ext4_feat, &ext4_feat_ktype, |
437 | NULL, "features"); | 442 | NULL, "features"); |
438 | if (ret) | 443 | if (ret) { |
444 | kobject_put(&ext4_feat); | ||
439 | kset_unregister(&ext4_kset); | 445 | kset_unregister(&ext4_kset); |
440 | else | 446 | } else { |
441 | ext4_proc_root = proc_mkdir(proc_dirname, NULL); | 447 | ext4_proc_root = proc_mkdir(proc_dirname, NULL); |
448 | } | ||
442 | return ret; | 449 | return ret; |
443 | } | 450 | } |
444 | 451 | ||