add patch create-ext4_feat-kobject-dynamically
[ext4-patch-queue.git] / create-ext4_feat-kobject-dynamically
blobc4774ec9ea151be998eb9b855f422f90a62a1c8a
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>
10 ---
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
16 --- a/fs/ext4/sysfs.c
17 +++ b/fs/ext4/sysfs.c
18 @@ -10,6 +10,7 @@
19  #include <linux/time.h>
20  #include <linux/fs.h>
21  #include <linux/seq_file.h>
22 +#include <linux/slab.h>
23  #include <linux/proc_fs.h>
25  #include "ext4.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,
31  };
33 -static struct kobject ext4_feat = {
34 -       .kset   = &ext4_kset,
35 -};
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)
41                 return ret;
42         }
44 -       ret = kobject_init_and_add(&ext4_feat, &ext4_feat_ktype,
45 -                                  NULL, "features");
46 -       if (ret) {
47 -               kobject_put(&ext4_feat);
48 -               kset_unregister(&ext4_kset);
49 -       } else {
50 -               ext4_proc_root = proc_mkdir(proc_dirname, NULL);
51 +       ext4_feat = kzalloc(sizeof(*ext4_feat), GFP_KERNEL);
52 +       if (!ext4_feat) {
53 +               ret = -ENOMEM;
54 +               goto kset_err;
55         }
57 +       ext4_feat->kset = &ext4_kset;
58 +       ret = kobject_init_and_add(ext4_feat, &ext4_feat_ktype,
59 +                                  NULL, "features");
60 +       if (ret)
61 +               goto feat_err;
63 +       ext4_proc_root = proc_mkdir(proc_dirname, NULL);
64 +       return ret;
66 +feat_err:
67 +       kobject_put(ext4_feat);
68 +kset_err:
69 +       kset_unregister(&ext4_kset);
70         return ret;
71  }
73  void ext4_exit_sysfs(void)
74  {
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;
80 -- 
81 2.14.3