1 ext4: create ext4_kset dynamically
3 From: Riccardo Schirone <sirmy15@gmail.com>
5 ksets contain a kobject and they should always be allocated dynamically,
6 because it is unknown to whoever creates them when ksets can be
9 Signed-off-by: Riccardo Schirone <sirmy15@gmail.com>
10 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
12 fs/ext4/sysfs.c | 39 +++++++++++++++++++++++++--------------
13 1 file changed, 25 insertions(+), 14 deletions(-)
15 diff --git a/fs/ext4/sysfs.c b/fs/ext4/sysfs.c
16 index 192ade7d6fe6..1205261f130c 100644
19 @@ -330,6 +330,13 @@ static void ext4_sb_release(struct kobject *kobj)
20 complete(&sbi->s_kobj_unregister);
23 +static void ext4_kset_release(struct kobject *kobj)
25 + struct kset *kset = container_of(kobj, struct kset, kobj);
30 static const struct sysfs_ops ext4_attr_ops = {
31 .show = ext4_attr_show,
32 .store = ext4_attr_store,
33 @@ -343,11 +350,10 @@ static struct kobj_type ext4_sb_ktype = {
35 static struct kobj_type ext4_ktype = {
36 .sysfs_ops = &ext4_attr_ops,
37 + .release = ext4_kset_release,
40 -static struct kset ext4_kset = {
41 - .kobj = {.ktype = &ext4_ktype},
43 +static struct kset *ext4_kset;
45 static struct kobj_type ext4_feat_ktype = {
46 .default_attrs = ext4_feat_attrs,
47 @@ -392,7 +398,7 @@ int ext4_register_sysfs(struct super_block *sb)
48 const struct ext4_proc_files *p;
51 - sbi->s_kobj.kset = &ext4_kset;
52 + sbi->s_kobj.kset = ext4_kset;
53 init_completion(&sbi->s_kobj_unregister);
54 err = kobject_init_and_add(&sbi->s_kobj, &ext4_sb_ktype, NULL,
56 @@ -430,13 +436,16 @@ int __init ext4_init_sysfs(void)
60 - kobject_set_name(&ext4_kset.kobj, "ext4");
61 - ext4_kset.kobj.parent = fs_kobj;
62 - ret = kset_register(&ext4_kset);
64 - kset_unregister(&ext4_kset);
67 + ext4_kset = kzalloc(sizeof(*ext4_kset), GFP_KERNEL);
71 + kobject_set_name(&ext4_kset->kobj, "ext4");
72 + ext4_kset->kobj.parent = fs_kobj;
73 + ext4_kset->kobj.ktype = &ext4_ktype;
74 + ret = kset_register(ext4_kset);
78 ext4_feat = kzalloc(sizeof(*ext4_feat), GFP_KERNEL);
80 @@ -444,7 +453,7 @@ int __init ext4_init_sysfs(void)
84 - ext4_feat->kset = &ext4_kset;
85 + ext4_feat->kset = ext4_kset;
86 ret = kobject_init_and_add(ext4_feat, &ext4_feat_ktype,
89 @@ -456,14 +465,16 @@ int __init ext4_init_sysfs(void)
91 kobject_put(ext4_feat);
93 - kset_unregister(&ext4_kset);
94 + kset_unregister(ext4_kset);
99 void ext4_exit_sysfs(void)
101 kobject_put(ext4_feat);
102 - kset_unregister(&ext4_kset);
103 + kset_unregister(ext4_kset);
105 remove_proc_entry(proc_dirname, NULL);
106 ext4_proc_root = NULL;