ocfs2-devel.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
* [Ocfs2-devel] [PATCH v3 01/10] kobject: introduce kobject_del_and_put()
@ 2023-03-22 16:58 Yangtao Li via Ocfs2-devel
  2023-03-22 23:31 ` Damien Le Moal via Ocfs2-devel
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Yangtao Li via Ocfs2-devel @ 2023-03-22 16:58 UTC (permalink / raw)
  To: clm, josef, dsterba, xiang, chao, huyue2, jefflexu, jaegeuk,
	trond.myklebust, anna, konishi.ryusuke, mark, jlbec, joseph.qi,
	richard, djwong, damien.lemoal, naohiro.aota, jth, gregkh,
	rafael
  Cc: linux-nfs, linux-nilfs, Yangtao Li, linux-kernel,
	linux-f2fs-devel, linux-xfs, linux-mtd, ocfs2-devel,
	linux-fsdevel, linux-erofs, linux-btrfs

There are plenty of using kobject_del() and kobject_put() together
in the kernel tree. This patch wraps these two calls in a single helper.

Signed-off-by: Yangtao Li <frank.li@vivo.com>
---
v3:
-convert to inline helper
v2:
-add kobject_del_and_put() users
 include/linux/kobject.h | 13 +++++++++++++
 lib/kobject.c           |  3 +--
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/include/linux/kobject.h b/include/linux/kobject.h
index bdab370a24f4..e21b7c22e355 100644
--- a/include/linux/kobject.h
+++ b/include/linux/kobject.h
@@ -112,6 +112,19 @@ extern struct kobject * __must_check kobject_get_unless_zero(
 						struct kobject *kobj);
 extern void kobject_put(struct kobject *kobj);
 
+/**
+ * kobject_del_and_put() - Delete kobject.
+ * @kobj: object.
+ *
+ * Unlink kobject from hierarchy and decrement the refcount.
+ * If refcount is 0, call kobject_cleanup().
+ */
+static inline void kobject_del_and_put(struct kobject *kobj)
+{
+	kobject_del(kobj);
+	kobject_put(kobj);
+}
+
 extern const void *kobject_namespace(const struct kobject *kobj);
 extern void kobject_get_ownership(const struct kobject *kobj,
 				  kuid_t *uid, kgid_t *gid);
diff --git a/lib/kobject.c b/lib/kobject.c
index f79a434e1231..e6c5a3ff1c53 100644
--- a/lib/kobject.c
+++ b/lib/kobject.c
@@ -876,8 +876,7 @@ void kset_unregister(struct kset *k)
 {
 	if (!k)
 		return;
-	kobject_del(&k->kobj);
-	kobject_put(&k->kobj);
+	kobject_del_and_put(&k->kobj);
 }
 EXPORT_SYMBOL(kset_unregister);
 
-- 
2.35.1


_______________________________________________
Ocfs2-devel mailing list
Ocfs2-devel@oss.oracle.com
https://oss.oracle.com/mailman/listinfo/ocfs2-devel

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

* Re: [Ocfs2-devel] [PATCH v3 01/10] kobject: introduce kobject_del_and_put()
  2023-03-22 16:58 [Ocfs2-devel] [PATCH v3 01/10] kobject: introduce kobject_del_and_put() Yangtao Li via Ocfs2-devel
@ 2023-03-22 23:31 ` Damien Le Moal via Ocfs2-devel
  2023-03-23  5:16 ` Ming Lei via Ocfs2-devel
  2023-03-23 12:26 ` Greg KH via Ocfs2-devel
  2 siblings, 0 replies; 5+ messages in thread
From: Damien Le Moal via Ocfs2-devel @ 2023-03-22 23:31 UTC (permalink / raw)
  To: Yangtao Li, clm, josef, dsterba, xiang, chao, huyue2, jefflexu,
	jaegeuk, trond.myklebust, anna, konishi.ryusuke, mark, jlbec,
	joseph.qi, richard, djwong, naohiro.aota, jth, gregkh, rafael
  Cc: linux-nfs, linux-nilfs, linux-kernel, linux-f2fs-devel,
	linux-xfs, linux-mtd, ocfs2-devel, linux-fsdevel, linux-erofs,
	linux-btrfs

On 3/23/23 01:58, Yangtao Li wrote:
> There are plenty of using kobject_del() and kobject_put() together
> in the kernel tree. This patch wraps these two calls in a single helper.
> 
> Signed-off-by: Yangtao Li <frank.li@vivo.com>
> ---
> v3:
> -convert to inline helper
> v2:
> -add kobject_del_and_put() users
>  include/linux/kobject.h | 13 +++++++++++++
>  lib/kobject.c           |  3 +--
>  2 files changed, 14 insertions(+), 2 deletions(-)
> 
> diff --git a/include/linux/kobject.h b/include/linux/kobject.h
> index bdab370a24f4..e21b7c22e355 100644
> --- a/include/linux/kobject.h
> +++ b/include/linux/kobject.h
> @@ -112,6 +112,19 @@ extern struct kobject * __must_check kobject_get_unless_zero(
>  						struct kobject *kobj);
>  extern void kobject_put(struct kobject *kobj);
>  
> +/**
> + * kobject_del_and_put() - Delete kobject.
> + * @kobj: object.
> + *
> + * Unlink kobject from hierarchy and decrement the refcount.

Unlink kobject from hierarchy and decrement its refcount.

> + * If refcount is 0, call kobject_cleanup().

That is done by kobject_put() and not explicitly done directly in this helper.
So I would not mention this to avoid confusion as you otherwise have a
description that does not match the code we can see here.

With that fixed, this looks OK to me, so feel free to add:

Reviewed-by: Damien Le Moal <damien.lemoal@opensource.wdc.com>

> + */
> +static inline void kobject_del_and_put(struct kobject *kobj)
> +{
> +	kobject_del(kobj);
> +	kobject_put(kobj);
> +}
> +
>  extern const void *kobject_namespace(const struct kobject *kobj);
>  extern void kobject_get_ownership(const struct kobject *kobj,
>  				  kuid_t *uid, kgid_t *gid);
> diff --git a/lib/kobject.c b/lib/kobject.c
> index f79a434e1231..e6c5a3ff1c53 100644
> --- a/lib/kobject.c
> +++ b/lib/kobject.c
> @@ -876,8 +876,7 @@ void kset_unregister(struct kset *k)
>  {
>  	if (!k)
>  		return;
> -	kobject_del(&k->kobj);
> -	kobject_put(&k->kobj);
> +	kobject_del_and_put(&k->kobj);

Nit: You could simplify this one to be:

	if (k)
		kobject_del_and_put(&k->kobj);

and drop the return line.

>  }
>  EXPORT_SYMBOL(kset_unregister);
>  

-- 
Damien Le Moal
Western Digital Research


_______________________________________________
Ocfs2-devel mailing list
Ocfs2-devel@oss.oracle.com
https://oss.oracle.com/mailman/listinfo/ocfs2-devel

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

* Re: [Ocfs2-devel] [PATCH v3 01/10] kobject: introduce kobject_del_and_put()
  2023-03-22 16:58 [Ocfs2-devel] [PATCH v3 01/10] kobject: introduce kobject_del_and_put() Yangtao Li via Ocfs2-devel
  2023-03-22 23:31 ` Damien Le Moal via Ocfs2-devel
@ 2023-03-23  5:16 ` Ming Lei via Ocfs2-devel
  2023-04-04 13:30   ` Yangtao Li via Ocfs2-devel
  2023-03-23 12:26 ` Greg KH via Ocfs2-devel
  2 siblings, 1 reply; 5+ messages in thread
From: Ming Lei via Ocfs2-devel @ 2023-03-23  5:16 UTC (permalink / raw)
  To: Yangtao Li
  Cc: rafael, linux-mtd, naohiro.aota, linux-nilfs, richard,
	trond.myklebust, xiang, chao, josef, ming.lei, huyue2, dsterba,
	jefflexu, jaegeuk, konishi.ryusuke, linux-nfs, clm, gregkh,
	linux-kernel, linux-f2fs-devel, linux-xfs, ocfs2-devel, anna,
	linux-fsdevel, jth, linux-erofs, damien.lemoal, linux-btrfs

On Thu, Mar 23, 2023 at 12:58:30AM +0800, Yangtao Li wrote:
> There are plenty of using kobject_del() and kobject_put() together
> in the kernel tree. This patch wraps these two calls in a single helper.
> 
> Signed-off-by: Yangtao Li <frank.li@vivo.com>
> ---
> v3:
> -convert to inline helper
> v2:
> -add kobject_del_and_put() users
>  include/linux/kobject.h | 13 +++++++++++++
>  lib/kobject.c           |  3 +--
>  2 files changed, 14 insertions(+), 2 deletions(-)
> 
> diff --git a/include/linux/kobject.h b/include/linux/kobject.h
> index bdab370a24f4..e21b7c22e355 100644
> --- a/include/linux/kobject.h
> +++ b/include/linux/kobject.h
> @@ -112,6 +112,19 @@ extern struct kobject * __must_check kobject_get_unless_zero(
>  						struct kobject *kobj);
>  extern void kobject_put(struct kobject *kobj);
>  
> +/**
> + * kobject_del_and_put() - Delete kobject.
> + * @kobj: object.
> + *
> + * Unlink kobject from hierarchy and decrement the refcount.
> + * If refcount is 0, call kobject_cleanup().
> + */
> +static inline void kobject_del_and_put(struct kobject *kobj)
> +{
> +	kobject_del(kobj);
> +	kobject_put(kobj);
> +}

kobject_put() actually covers kobject removal automatically, which is
single stage removal. So if you see the two called together, it is
safe to kill kobject_del() directly.


thanks,
Ming


_______________________________________________
Ocfs2-devel mailing list
Ocfs2-devel@oss.oracle.com
https://oss.oracle.com/mailman/listinfo/ocfs2-devel

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

* Re: [Ocfs2-devel] [PATCH v3 01/10] kobject: introduce kobject_del_and_put()
  2023-03-22 16:58 [Ocfs2-devel] [PATCH v3 01/10] kobject: introduce kobject_del_and_put() Yangtao Li via Ocfs2-devel
  2023-03-22 23:31 ` Damien Le Moal via Ocfs2-devel
  2023-03-23  5:16 ` Ming Lei via Ocfs2-devel
@ 2023-03-23 12:26 ` Greg KH via Ocfs2-devel
  2 siblings, 0 replies; 5+ messages in thread
From: Greg KH via Ocfs2-devel @ 2023-03-23 12:26 UTC (permalink / raw)
  To: Yangtao Li
  Cc: rafael, linux-mtd, naohiro.aota, linux-nilfs, richard,
	trond.myklebust, xiang, chao, josef, huyue2, dsterba, jefflexu,
	jaegeuk, konishi.ryusuke, linux-nfs, clm, linux-kernel,
	linux-f2fs-devel, linux-xfs, ocfs2-devel, anna, linux-fsdevel,
	jth, linux-erofs, damien.lemoal, linux-btrfs

On Thu, Mar 23, 2023 at 12:58:30AM +0800, Yangtao Li wrote:
> There are plenty of using kobject_del() and kobject_put() together
> in the kernel tree. This patch wraps these two calls in a single helper.
> 
> Signed-off-by: Yangtao Li <frank.li@vivo.com>
> ---
> v3:
> -convert to inline helper
> v2:
> -add kobject_del_and_put() users
>  include/linux/kobject.h | 13 +++++++++++++
>  lib/kobject.c           |  3 +--
>  2 files changed, 14 insertions(+), 2 deletions(-)

Meta-comment, something is wrong with this email as it is not linked to
the rest of the series.

You can see that by looking at this message in lore.kernel.org:
	https://lore.kernel.org/r/20230322165830.55071-1-frank.li@vivo.com

No 2-10 patches linked there (they show up as a separate series.)

So even if I wanted to take this series now, we can't as our tools can't
find them...

thanks,

greg k-h

_______________________________________________
Ocfs2-devel mailing list
Ocfs2-devel@oss.oracle.com
https://oss.oracle.com/mailman/listinfo/ocfs2-devel

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

* Re: [Ocfs2-devel] [PATCH v3 01/10] kobject: introduce kobject_del_and_put()
  2023-03-23  5:16 ` Ming Lei via Ocfs2-devel
@ 2023-04-04 13:30   ` Yangtao Li via Ocfs2-devel
  0 siblings, 0 replies; 5+ messages in thread
From: Yangtao Li via Ocfs2-devel @ 2023-04-04 13:30 UTC (permalink / raw)
  To: ming.lei
  Cc: rafael, linux-mtd, naohiro.aota, linux-nilfs, richard,
	damien.lemoal, trond.myklebust, xiang, frank.li, chao, josef,
	huyue2, dsterba, jefflexu, jaegeuk, konishi.ryusuke, linux-nfs,
	clm, gregkh, linux-kernel, linux-f2fs-devel, linux-xfs,
	ocfs2-devel, anna, linux-fsdevel, jth, linux-erofs, linux-btrfs

> kobject_put() actually covers kobject removal automatically, which is
> single stage removal. So if you see the two called together, it is
> safe to kill kobject_del() directly.

If the reference count is not abnormal, kobject_put() does contain
what kobject_del() does.

Thx,
Yangtao

_______________________________________________
Ocfs2-devel mailing list
Ocfs2-devel@oss.oracle.com
https://oss.oracle.com/mailman/listinfo/ocfs2-devel

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

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

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-22 16:58 [Ocfs2-devel] [PATCH v3 01/10] kobject: introduce kobject_del_and_put() Yangtao Li via Ocfs2-devel
2023-03-22 23:31 ` Damien Le Moal via Ocfs2-devel
2023-03-23  5:16 ` Ming Lei via Ocfs2-devel
2023-04-04 13:30   ` Yangtao Li via Ocfs2-devel
2023-03-23 12:26 ` Greg KH via Ocfs2-devel

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