1 ext4: create ext4_feat kobject dynamically
3 From: Riccardo Schirone <sirmy15@gmail.com>
5 kobjects should always be allocated dynamically, because it is unknown
6 to whoever creates them when kobjects can be released.
8 Signed-off-by: Riccardo Schirone <sirmy15@gmail.com>
9 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
11 fs/ext4/sysfs.c | 33 ++++++++++++++++++++++-----------
12 1 file changed, 22 insertions(+), 11 deletions(-)
14 diff --git a/fs/ext4/sysfs.c b/fs/ext4/sysfs.c
15 index b096e157934f..c447f23cc876 100644
19 #include <linux/time.h>
21 #include <linux/seq_file.h>
22 +#include <linux/slab.h>
23 #include <linux/proc_fs.h>
26 @@ -350,11 +351,10 @@ static struct kset ext4_kset = {
27 static struct kobj_type ext4_feat_ktype = {
28 .default_attrs = ext4_feat_attrs,
29 .sysfs_ops = &ext4_attr_ops,
30 + .release = (void (*)(struct kobject *))kfree,
33 -static struct kobject ext4_feat = {
36 +static struct kobject *ext4_feat;
38 #define PROC_FILE_SHOW_DEFN(name) \
39 static int name##_open(struct inode *inode, struct file *file) \
40 @@ -437,20 +437,31 @@ int __init ext4_init_sysfs(void)
44 - ret = kobject_init_and_add(&ext4_feat, &ext4_feat_ktype,
47 - kobject_put(&ext4_feat);
48 - kset_unregister(&ext4_kset);
50 - ext4_proc_root = proc_mkdir(proc_dirname, NULL);
51 + ext4_feat = kzalloc(sizeof(*ext4_feat), GFP_KERNEL);
57 + ext4_feat->kset = &ext4_kset;
58 + ret = kobject_init_and_add(ext4_feat, &ext4_feat_ktype,
63 + ext4_proc_root = proc_mkdir(proc_dirname, NULL);
67 + kobject_put(ext4_feat);
69 + kset_unregister(&ext4_kset);
73 void ext4_exit_sysfs(void)
75 - kobject_put(&ext4_feat);
76 + kobject_put(ext4_feat);
77 kset_unregister(&ext4_kset);
78 remove_proc_entry(proc_dirname, NULL);
79 ext4_proc_root = NULL;