From: Riccardo Schirone <sirmy15@gmail.com>
To: tytso@mit.edu, adilger.kernel@dilger.ca, linux-ext4@vger.kernel.org
Cc: Riccardo Schirone <sirmy15@gmail.com>
Subject: [PATCH 2/3] fs/ext4: create ext4_feat kobject dynamically
Date: Tue, 28 Nov 2017 00:18:00 +0100 [thread overview]
Message-ID: <20171127231801.27652-3-sirmy15@gmail.com> (raw)
In-Reply-To: <20171127231801.27652-1-sirmy15@gmail.com>
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>
---
fs/ext4/sysfs.c | 33 ++++++++++++++++++++++-----------
1 file changed, 22 insertions(+), 11 deletions(-)
diff --git a/fs/ext4/sysfs.c b/fs/ext4/sysfs.c
index b096e157934f..c447f23cc876 100644
--- a/fs/ext4/sysfs.c
+++ b/fs/ext4/sysfs.c
@@ -10,6 +10,7 @@
#include <linux/time.h>
#include <linux/fs.h>
#include <linux/seq_file.h>
+#include <linux/slab.h>
#include <linux/proc_fs.h>
#include "ext4.h"
@@ -350,11 +351,10 @@ static struct kset ext4_kset = {
static struct kobj_type ext4_feat_ktype = {
.default_attrs = ext4_feat_attrs,
.sysfs_ops = &ext4_attr_ops,
+ .release = (void (*)(struct kobject *))kfree,
};
-static struct kobject ext4_feat = {
- .kset = &ext4_kset,
-};
+static struct kobject *ext4_feat;
#define PROC_FILE_SHOW_DEFN(name) \
static int name##_open(struct inode *inode, struct file *file) \
@@ -437,20 +437,31 @@ int __init ext4_init_sysfs(void)
return ret;
}
- ret = kobject_init_and_add(&ext4_feat, &ext4_feat_ktype,
- NULL, "features");
- if (ret) {
- kobject_put(&ext4_feat);
- kset_unregister(&ext4_kset);
- } else {
- ext4_proc_root = proc_mkdir(proc_dirname, NULL);
+ ext4_feat = kzalloc(sizeof(*ext4_feat), GFP_KERNEL);
+ if (!ext4_feat) {
+ ret = -ENOMEM;
+ goto kset_err;
}
+
+ ext4_feat->kset = &ext4_kset;
+ ret = kobject_init_and_add(ext4_feat, &ext4_feat_ktype,
+ NULL, "features");
+ if (ret)
+ goto feat_err;
+
+ ext4_proc_root = proc_mkdir(proc_dirname, NULL);
+ return ret;
+
+feat_err:
+ kobject_put(ext4_feat);
+kset_err:
+ kset_unregister(&ext4_kset);
return ret;
}
void ext4_exit_sysfs(void)
{
- kobject_put(&ext4_feat);
+ kobject_put(ext4_feat);
kset_unregister(&ext4_kset);
remove_proc_entry(proc_dirname, NULL);
ext4_proc_root = NULL;
--
2.14.3
next prev parent reply other threads:[~2017-11-27 23:18 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-27 23:17 [PATCH 0/3] Improve kobject handling in fs/ext4 Riccardo Schirone
2017-11-27 23:17 ` [PATCH 1/3] fs/ext4: release kobject/kset even when init/register fail Riccardo Schirone
2017-11-27 23:34 ` Andreas Dilger
2017-11-28 11:03 ` Riccardo S.
2018-01-11 20:10 ` Theodore Ts'o
2017-11-27 23:18 ` Riccardo Schirone [this message]
2018-01-11 20:17 ` [PATCH 2/3] fs/ext4: create ext4_feat kobject dynamically Theodore Ts'o
2017-11-27 23:18 ` [PATCH 3/3] fs/ext4: create ext4_kset dynamically Riccardo Schirone
2017-11-27 23:44 ` Andreas Dilger
2017-11-28 10:51 ` Riccardo S.
2018-01-11 20:40 ` Theodore Ts'o
2017-11-28 3:51 ` [PATCH 0/3] Improve kobject handling in fs/ext4 Theodore Ts'o
2017-11-28 10:50 ` Riccardo S.
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20171127231801.27652-3-sirmy15@gmail.com \
--to=sirmy15@gmail.com \
--cc=adilger.kernel@dilger.ca \
--cc=linux-ext4@vger.kernel.org \
--cc=tytso@mit.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).