From: Yangtao Li <frank.li@vivo.com>
To: Gao Xiang <xiang@kernel.org>, Chao Yu <chao@kernel.org>,
Yue Hu <huyue2@coolpad.com>,
Jeffle Xu <jefflexu@linux.alibaba.com>
Cc: Yangtao Li <frank.li@vivo.com>,
linux-erofs@lists.ozlabs.org, linux-kernel@vger.kernel.org
Subject: [PATCH] erofs: don't access kobject object members directly
Date: Wed, 12 Apr 2023 11:11:10 +0800 [thread overview]
Message-ID: <20230412031110.8965-1-frank.li@vivo.com> (raw)
It is better not to directly access the internal members of the
kobject object, especially kobject_init_and_add() may failure.
BTW remove unnecessary kobject_del(), kobject_put() actually covers
kobject removal automatically, which is single stage removal.
Signed-off-by: Yangtao Li <frank.li@vivo.com>
---
fs/erofs/internal.h | 1 +
fs/erofs/sysfs.c | 4 ++--
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h
index f675050af2bb..f364b1e9b35b 100644
--- a/fs/erofs/internal.h
+++ b/fs/erofs/internal.h
@@ -177,6 +177,7 @@ struct erofs_sb_info {
/* sysfs support */
struct kobject s_kobj; /* /sys/fs/erofs/<devname> */
struct completion s_kobj_unregister;
+ bool sysfs_registered;
/* fscache support */
struct fscache_volume *volume;
diff --git a/fs/erofs/sysfs.c b/fs/erofs/sysfs.c
index 435e515c0792..c38018d3c442 100644
--- a/fs/erofs/sysfs.c
+++ b/fs/erofs/sysfs.c
@@ -228,6 +228,7 @@ int erofs_register_sysfs(struct super_block *sb)
kfree(str);
if (err)
goto put_sb_kobj;
+ sbi->sysfs_registered = true;
return 0;
put_sb_kobj:
@@ -240,8 +241,7 @@ void erofs_unregister_sysfs(struct super_block *sb)
{
struct erofs_sb_info *sbi = EROFS_SB(sb);
- if (sbi->s_kobj.state_in_sysfs) {
- kobject_del(&sbi->s_kobj);
+ if (sbi->sysfs_registered) {
kobject_put(&sbi->s_kobj);
wait_for_completion(&sbi->s_kobj_unregister);
}
--
2.35.1
next reply other threads:[~2023-04-12 3:11 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-12 3:11 Yangtao Li [this message]
2023-04-12 3:24 ` Gao Xiang
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=20230412031110.8965-1-frank.li@vivo.com \
--to=frank.li@vivo.com \
--cc=chao@kernel.org \
--cc=huyue2@coolpad.com \
--cc=jefflexu@linux.alibaba.com \
--cc=linux-erofs@lists.ozlabs.org \
--cc=linux-kernel@vger.kernel.org \
--cc=xiang@kernel.org \
/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
all inboxes | Powered by JetHome®