[2/2] erofs: remove unnecessary kobject_del()

Message ID 20230404142102.13226-2-frank.li@vivo.com
State New
Headers
Series [1/2] f2fs: remove unnecessary kobject_del() |

Commit Message

李扬韬 April 4, 2023, 2:21 p.m. UTC
  kobject_put() actually covers kobject removal automatically, which is
single stage removal. So it is safe to kill kobject_del() directly.

Signed-off-by: Yangtao Li <frank.li@vivo.com>
---
 fs/erofs/sysfs.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
  

Comments

Gao Xiang April 6, 2023, 3:52 a.m. UTC | #1
Hi Yangtao,

On 2023/4/4 22:21, Yangtao Li wrote:
> kobject_put() actually covers kobject removal automatically, which is
> single stage removal. So it is safe to kill kobject_del() directly.
> 
> Signed-off-by: Yangtao Li <frank.li@vivo.com>

Would you mind taking a look at
commit a942da24abc5 ("fs: erofs: add sanity check for kobject in erofs_unregister_sysfs")

, which could be "git-blame"ed (I'd suggest looking into these
blame first), and the related discussion was:

https://lore.kernel.org/r/CAD-N9QXNx=p3-QoWzk6pCznF32CZy8kM3vvo8mamfZZ9CpUKdw@mail.gmail.com
https://lore.kernel.org/r/20220315075152.63789-1-dzm91@hust.edu.cn

TL;DR: I guess it could be fixed as below if kobject_del() could
be killed safely:

	if (sbi->s_kobj.state_in_sysfs) {
		kobject_put(&sbi->s_kobj);
		wait_for_completion(&sbi->s_kobj_unregister);
	}

Thanks,
Gao Xiang


> ---
>   fs/erofs/sysfs.c | 7 ++-----
>   1 file changed, 2 insertions(+), 5 deletions(-)
> 
> diff --git a/fs/erofs/sysfs.c b/fs/erofs/sysfs.c
> index 435e515c0792..c3ba981b4472 100644
> --- a/fs/erofs/sysfs.c
> +++ b/fs/erofs/sysfs.c
> @@ -240,11 +240,8 @@ 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);
> -		kobject_put(&sbi->s_kobj);
> -		wait_for_completion(&sbi->s_kobj_unregister);
> -	}
> +	kobject_put(&sbi->s_kobj);
> +	wait_for_completion(&sbi->s_kobj_unregister);
>   }
>   
>   int __init erofs_init_sysfs(void)
  
李扬韬 April 6, 2023, 9:41 a.m. UTC | #2
HI Gao Xiang,

> Would you mind taking a look at
> commit a942da24abc5 ("fs: erofs: add sanity check for kobject in erofs_unregister_sysfs")
>
> , which could be "git-blame"ed (I'd suggest looking into these
> blame first), and the related discussion was:
>
> https://lore.kernel.org/r/CAD-N9QXNx=p3-QoWzk6pCznF32CZy8kM3vvo8mamfZZ9CpUKdw@mail.gmail.com
> https://lore.kernel.org/r/20220315075152.63789-1-dzm91@hust.edu.cn

> TL;DR: I guess it could be fixed as below if kobject_del() could
> : be killed safely:
>
> 	if (sbi->s_kobj.state_in_sysfs) {
> 		kobject_put(&sbi->s_kobj);
> 		wait_for_completion(&sbi->s_kobj_unregister);
> 	}

Thanks for your review and detailed explanation.

MBR,
Yangtao
  

Patch

diff --git a/fs/erofs/sysfs.c b/fs/erofs/sysfs.c
index 435e515c0792..c3ba981b4472 100644
--- a/fs/erofs/sysfs.c
+++ b/fs/erofs/sysfs.c
@@ -240,11 +240,8 @@  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);
-		kobject_put(&sbi->s_kobj);
-		wait_for_completion(&sbi->s_kobj_unregister);
-	}
+	kobject_put(&sbi->s_kobj);
+	wait_for_completion(&sbi->s_kobj_unregister);
 }
 
 int __init erofs_init_sysfs(void)