aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRiccardo Schirone <sirmy15@gmail.com>2018-01-11 15:11:32 -0500
committerTheodore Ts'o <tytso@mit.edu>2018-01-11 15:11:32 -0500
commitb99fee58a20ab8e0557cce87b6f187e325993142 (patch)
tree41d6f830358a3d851cd12622ccc810492f073b5d
parent95c4df029374d8c09ad36c961e7a14a1d3ac6a6f (diff)
ext4: create ext4_feat kobject dynamically
kobjects should always be allocated dynamically, because it is unknown to whoever creates them when kobjects can be released. Signed-off-by: Riccardo Schirone <sirmy15@gmail.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
-rw-r--r--fs/ext4/sysfs.c33
1 files changed, 22 insertions, 11 deletions
diff --git a/fs/ext4/sysfs.c b/fs/ext4/sysfs.c
index 4389fe4893c2..192ade7d6fe6 100644
--- a/fs/ext4/sysfs.c
+++ b/fs/ext4/sysfs.c
@@ -11,6 +11,7 @@
11#include <linux/time.h> 11#include <linux/time.h>
12#include <linux/fs.h> 12#include <linux/fs.h>
13#include <linux/seq_file.h> 13#include <linux/seq_file.h>
14#include <linux/slab.h>
14#include <linux/proc_fs.h> 15#include <linux/proc_fs.h>
15 16
16#include "ext4.h" 17#include "ext4.h"
@@ -351,11 +352,10 @@ static struct kset ext4_kset = {
351static struct kobj_type ext4_feat_ktype = { 352static struct kobj_type ext4_feat_ktype = {
352 .default_attrs = ext4_feat_attrs, 353 .default_attrs = ext4_feat_attrs,
353 .sysfs_ops = &ext4_attr_ops, 354 .sysfs_ops = &ext4_attr_ops,
355 .release = (void (*)(struct kobject *))kfree,
354}; 356};
355 357
356static struct kobject ext4_feat = { 358static struct kobject *ext4_feat;
357 .kset = &ext4_kset,
358};
359 359
360#define PROC_FILE_SHOW_DEFN(name) \ 360#define PROC_FILE_SHOW_DEFN(name) \
361static int name##_open(struct inode *inode, struct file *file) \ 361static int name##_open(struct inode *inode, struct file *file) \
@@ -438,20 +438,31 @@ int __init ext4_init_sysfs(void)
438 return ret; 438 return ret;
439 } 439 }
440 440
441 ret = kobject_init_and_add(&ext4_feat, &ext4_feat_ktype, 441 ext4_feat = kzalloc(sizeof(*ext4_feat), GFP_KERNEL);
442 NULL, "features"); 442 if (!ext4_feat) {
443 if (ret) { 443 ret = -ENOMEM;
444 kobject_put(&ext4_feat); 444 goto kset_err;
445 kset_unregister(&ext4_kset);
446 } else {
447 ext4_proc_root = proc_mkdir(proc_dirname, NULL);
448 } 445 }
446
447 ext4_feat->kset = &ext4_kset;
448 ret = kobject_init_and_add(ext4_feat, &ext4_feat_ktype,
449 NULL, "features");
450 if (ret)
451 goto feat_err;
452
453 ext4_proc_root = proc_mkdir(proc_dirname, NULL);
454 return ret;
455
456feat_err:
457 kobject_put(ext4_feat);
458kset_err:
459 kset_unregister(&ext4_kset);
449 return ret; 460 return ret;
450} 461}
451 462
452void ext4_exit_sysfs(void) 463void ext4_exit_sysfs(void)
453{ 464{
454 kobject_put(&ext4_feat); 465 kobject_put(ext4_feat);
455 kset_unregister(&ext4_kset); 466 kset_unregister(&ext4_kset);
456 remove_proc_entry(proc_dirname, NULL); 467 remove_proc_entry(proc_dirname, NULL);
457 ext4_proc_root = NULL; 468 ext4_proc_root = NULL;