diff mbox series

[1/3] kobject: introduce kobject_is_added()

Message ID 20230406093056.33916-1-frank.li@vivo.com (mailing list archive)
State Mainlined, archived
Headers show
Series [1/3] kobject: introduce kobject_is_added() | expand

Commit Message

Yangtao Li April 6, 2023, 9:30 a.m. UTC
Add kobject_is_added() to avoid consumers from directly accessing
the internal variables of kobject.

Signed-off-by: Yangtao Li <frank.li@vivo.com>
---
 include/linux/kobject.h | 5 +++++
 1 file changed, 5 insertions(+)

Comments

Greg KH April 6, 2023, 9:59 a.m. UTC | #1
On Thu, Apr 06, 2023 at 05:30:54PM +0800, Yangtao Li wrote:
> Add kobject_is_added() to avoid consumers from directly accessing
> the internal variables of kobject.
> 
> Signed-off-by: Yangtao Li <frank.li@vivo.com>
> ---
>  include/linux/kobject.h | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/include/linux/kobject.h b/include/linux/kobject.h
> index bdab370a24f4..b5cdb0c58729 100644
> --- a/include/linux/kobject.h
> +++ b/include/linux/kobject.h
> @@ -203,6 +203,11 @@ static inline const struct kobj_type *get_ktype(const struct kobject *kobj)
>  	return kobj->ktype;
>  }
>  
> +static inline int kobject_is_added(struct kobject *kobj)
> +{
> +	return kobj->state_in_sysfs;
> +}
> +

No, this implies that the caller is not doing something correctly as it
should always know if it has added a kobject or not.  Let me review the
please where you used this to find the problems there...

thanks,

greg k-h
diff mbox series

Patch

diff --git a/include/linux/kobject.h b/include/linux/kobject.h
index bdab370a24f4..b5cdb0c58729 100644
--- a/include/linux/kobject.h
+++ b/include/linux/kobject.h
@@ -203,6 +203,11 @@  static inline const struct kobj_type *get_ktype(const struct kobject *kobj)
 	return kobj->ktype;
 }
 
+static inline int kobject_is_added(struct kobject *kobj)
+{
+	return kobj->state_in_sysfs;
+}
+
 extern struct kobject *kset_find_obj(struct kset *, const char *);
 
 /* The global /sys/kernel/ kobject for people to chain off of */