linux-erofs.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] erofs: don't access kobject object members directly
@ 2023-04-12  3:11 Yangtao Li
  2023-04-12  3:24 ` Gao Xiang
  0 siblings, 1 reply; 2+ messages in thread
From: Yangtao Li @ 2023-04-12  3:11 UTC (permalink / raw)
  To: Gao Xiang, Chao Yu, Yue Hu, Jeffle Xu
  Cc: linux-erofs, linux-kernel, Yangtao Li

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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] erofs: don't access kobject object members directly
  2023-04-12  3:11 [PATCH] erofs: don't access kobject object members directly Yangtao Li
@ 2023-04-12  3:24 ` Gao Xiang
  0 siblings, 0 replies; 2+ messages in thread
From: Gao Xiang @ 2023-04-12  3:24 UTC (permalink / raw)
  To: Yangtao Li, Gao Xiang, Chao Yu, Yue Hu, Jeffle Xu, Huang Jianan,
	Greg KH, Dongliang Mu
  Cc: linux-erofs, linux-kernel

(+ Greg, Huang Jianan, Dongliang Mu)

On 2023/4/12 11:11, Yangtao Li wrote:
> 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.

Please at least Cc the proper people --- and write
the previous background to the commit message *again*.

I'd like to know the preferred way to do this since
the previous discussion is unfinished.

Also if you grep `state_in_sysfs`, actually there are
some similar in-tree usage, also device_is_registered() is
implemented like this:

static inline int device_is_registered(struct device *dev)
{
	return dev->kobj.state_in_sysfs;
}

Again, I'm not against this patch (I even prefer this one),
but you should Cc the proper people and finish the previous
topic first.

Thanks,
Gao Xiang

> 
> 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);
>   	}

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-04-12  3:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-12  3:11 [PATCH] erofs: don't access kobject object members directly Yangtao Li
2023-04-12  3:24 ` Gao Xiang

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).