* [PATCH 1/2] driver core: class: use lock_class_key already present in struct subsys_private
@ 2023-03-24 10:01 Greg Kroah-Hartman
2023-03-24 10:01 ` [PATCH 2/2] driver core: class.h: remove extern from function prototypes Greg Kroah-Hartman
2023-03-24 13:42 ` [PATCH 1/2] driver core: class: use lock_class_key already present in struct subsys_private Rafael J. Wysocki
0 siblings, 2 replies; 4+ messages in thread
From: Greg Kroah-Hartman @ 2023-03-24 10:01 UTC (permalink / raw)
To: linux-kernel; +Cc: Greg Kroah-Hartman, Rafael J. Wysocki
In commit 37e98d9bedb5 ("driver core: bus: move lock_class_key into
dynamic structure"), we moved the lock_class_key into the internal
structure shared by busses and classes, but only used it for buses.
Move the class code to use this structure as it is already present and
being allocated, instead of the statically allocated on-the-stack
variable that class_create() was using as part of a macro wrapper around
the core function call.
Cc: "Rafael J. Wysocki" <rafael@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
drivers/base/class.c | 15 +++++++++------
include/linux/device/class.h | 36 ++----------------------------------
2 files changed, 11 insertions(+), 40 deletions(-)
diff --git a/drivers/base/class.c b/drivers/base/class.c
index 3d65221b0dcb..dbaeb79ae917 100644
--- a/drivers/base/class.c
+++ b/drivers/base/class.c
@@ -154,9 +154,10 @@ static void class_remove_groups(struct class *cls,
return sysfs_remove_groups(&cls->p->subsys.kobj, groups);
}
-int __class_register(struct class *cls, struct lock_class_key *key)
+int class_register(struct class *cls)
{
struct subsys_private *cp;
+ struct lock_class_key *key;
int error;
pr_debug("device class '%s': registering\n", cls->name);
@@ -167,6 +168,8 @@ int __class_register(struct class *cls, struct lock_class_key *key)
klist_init(&cp->klist_devices, klist_class_dev_get, klist_class_dev_put);
INIT_LIST_HEAD(&cp->interfaces);
kset_init(&cp->glue_dirs);
+ key = &cp->lock_key;
+ lockdep_register_key(key);
__mutex_init(&cp->mutex, "subsys mutex", key);
error = kobject_set_name(&cp->subsys.kobj, "%s", cls->name);
if (error) {
@@ -201,7 +204,7 @@ int __class_register(struct class *cls, struct lock_class_key *key)
cls->p = NULL;
return error;
}
-EXPORT_SYMBOL_GPL(__class_register);
+EXPORT_SYMBOL_GPL(class_register);
void class_unregister(struct class *cls)
{
@@ -218,7 +221,7 @@ static void class_create_release(struct class *cls)
}
/**
- * __class_create - create a struct class structure
+ * class_create - create a struct class structure
* @name: pointer to a string for the name of this class.
* @key: the lock_class_key for this class; used by mutex lock debugging
*
@@ -230,7 +233,7 @@ static void class_create_release(struct class *cls)
* Note, the pointer created here is to be destroyed when finished by
* making a call to class_destroy().
*/
-struct class *__class_create(const char *name, struct lock_class_key *key)
+struct class *class_create(const char *name)
{
struct class *cls;
int retval;
@@ -244,7 +247,7 @@ struct class *__class_create(const char *name, struct lock_class_key *key)
cls->name = name;
cls->class_release = class_create_release;
- retval = __class_register(cls, key);
+ retval = class_register(cls);
if (retval)
goto error;
@@ -254,7 +257,7 @@ struct class *__class_create(const char *name, struct lock_class_key *key)
kfree(cls);
return ERR_PTR(retval);
}
-EXPORT_SYMBOL_GPL(__class_create);
+EXPORT_SYMBOL_GPL(class_create);
/**
* class_destroy - destroys a struct class structure
diff --git a/include/linux/device/class.h b/include/linux/device/class.h
index 75c1451fcc63..03d2f99f84c5 100644
--- a/include/linux/device/class.h
+++ b/include/linux/device/class.h
@@ -82,18 +82,9 @@ struct class_dev_iter {
extern struct kobject *sysfs_dev_block_kobj;
extern struct kobject *sysfs_dev_char_kobj;
-extern int __must_check __class_register(struct class *class,
- struct lock_class_key *key);
+extern int __must_check class_register(struct class *class);
extern void class_unregister(struct class *class);
-/* This is a #define to keep the compiler from merging different
- * instances of the __key variable */
-#define class_register(class) \
-({ \
- static struct lock_class_key __key; \
- __class_register(class, &__key); \
-})
-
struct class_compat;
struct class_compat *class_compat_register(const char *name);
void class_compat_unregister(struct class_compat *cls);
@@ -246,30 +237,7 @@ struct class_interface {
extern int __must_check class_interface_register(struct class_interface *);
extern void class_interface_unregister(struct class_interface *);
-extern struct class * __must_check __class_create(const char *name,
- struct lock_class_key *key);
+extern struct class * __must_check class_create(const char *name);
extern void class_destroy(struct class *cls);
-/* This is a #define to keep the compiler from merging different
- * instances of the __key variable */
-
-/**
- * class_create - create a struct class structure
- * @name: pointer to a string for the name of this class.
- *
- * This is used to create a struct class pointer that can then be used
- * in calls to device_create().
- *
- * Returns &struct class pointer on success, or ERR_PTR() on error.
- *
- * Note, the pointer created here is to be destroyed when finished by
- * making a call to class_destroy().
- */
-#define class_create(name) \
-({ \
- static struct lock_class_key __key; \
- __class_create(name, &__key); \
-})
-
-
#endif /* _DEVICE_CLASS_H_ */
--
2.40.0
^ permalink raw reply related [flat|nested] 4+ messages in thread* [PATCH 2/2] driver core: class.h: remove extern from function prototypes
2023-03-24 10:01 [PATCH 1/2] driver core: class: use lock_class_key already present in struct subsys_private Greg Kroah-Hartman
@ 2023-03-24 10:01 ` Greg Kroah-Hartman
2023-03-24 13:42 ` Rafael J. Wysocki
2023-03-24 13:42 ` [PATCH 1/2] driver core: class: use lock_class_key already present in struct subsys_private Rafael J. Wysocki
1 sibling, 1 reply; 4+ messages in thread
From: Greg Kroah-Hartman @ 2023-03-24 10:01 UTC (permalink / raw)
To: linux-kernel; +Cc: Greg Kroah-Hartman, Rafael J. Wysocki
The kernel coding style does not require 'extern' in function prototypes
in .h files, so remove them from include/linux/device/class.h as they
are not needed.
Cc: "Rafael J. Wysocki" <rafael@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
include/linux/device/class.h | 46 ++++++++++++++++--------------------
1 file changed, 20 insertions(+), 26 deletions(-)
diff --git a/include/linux/device/class.h b/include/linux/device/class.h
index 03d2f99f84c5..1dc7706cb42d 100644
--- a/include/linux/device/class.h
+++ b/include/linux/device/class.h
@@ -82,8 +82,9 @@ struct class_dev_iter {
extern struct kobject *sysfs_dev_block_kobj;
extern struct kobject *sysfs_dev_char_kobj;
-extern int __must_check class_register(struct class *class);
-extern void class_unregister(struct class *class);
+
+int __must_check class_register(struct class *class);
+void class_unregister(struct class *class);
struct class_compat;
struct class_compat *class_compat_register(const char *name);
@@ -93,19 +94,15 @@ int class_compat_create_link(struct class_compat *cls, struct device *dev,
void class_compat_remove_link(struct class_compat *cls, struct device *dev,
struct device *device_link);
-extern void class_dev_iter_init(struct class_dev_iter *iter,
- const struct class *class,
- const struct device *start,
- const struct device_type *type);
-extern struct device *class_dev_iter_next(struct class_dev_iter *iter);
-extern void class_dev_iter_exit(struct class_dev_iter *iter);
+void class_dev_iter_init(struct class_dev_iter *iter, const struct class *class,
+ const struct device *start, const struct device_type *type);
+struct device *class_dev_iter_next(struct class_dev_iter *iter);
+void class_dev_iter_exit(struct class_dev_iter *iter);
-extern int class_for_each_device(const struct class *class, const struct device *start,
- void *data,
- int (*fn)(struct device *dev, void *data));
-extern struct device *class_find_device(const struct class *class,
- const struct device *start, const void *data,
- int (*match)(struct device *, const void *));
+int class_for_each_device(const struct class *class, const struct device *start, void *data,
+ int (*fn)(struct device *dev, void *data));
+struct device *class_find_device(const struct class *class, const struct device *start,
+ const void *data, int (*match)(struct device *, const void *));
/**
* class_find_device_by_name - device iterator for locating a particular device
@@ -191,12 +188,10 @@ struct class_attribute {
#define CLASS_ATTR_WO(_name) \
struct class_attribute class_attr_##_name = __ATTR_WO(_name)
-extern int __must_check class_create_file_ns(const struct class *class,
- const struct class_attribute *attr,
- const void *ns);
-extern void class_remove_file_ns(const struct class *class,
- const struct class_attribute *attr,
- const void *ns);
+int __must_check class_create_file_ns(const struct class *class, const struct class_attribute *attr,
+ const void *ns);
+void class_remove_file_ns(const struct class *class, const struct class_attribute *attr,
+ const void *ns);
static inline int __must_check class_create_file(const struct class *class,
const struct class_attribute *attr)
@@ -223,8 +218,7 @@ struct class_attribute_string {
struct class_attribute_string class_attr_##_name = \
_CLASS_ATTR_STRING(_name, _mode, _str)
-extern ssize_t show_class_attr_string(struct class *class, struct class_attribute *attr,
- char *buf);
+ssize_t show_class_attr_string(struct class *class, struct class_attribute *attr, char *buf);
struct class_interface {
struct list_head node;
@@ -234,10 +228,10 @@ struct class_interface {
void (*remove_dev) (struct device *, struct class_interface *);
};
-extern int __must_check class_interface_register(struct class_interface *);
-extern void class_interface_unregister(struct class_interface *);
+int __must_check class_interface_register(struct class_interface *);
+void class_interface_unregister(struct class_interface *);
-extern struct class * __must_check class_create(const char *name);
-extern void class_destroy(struct class *cls);
+struct class * __must_check class_create(const char *name);
+void class_destroy(struct class *cls);
#endif /* _DEVICE_CLASS_H_ */
--
2.40.0
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH 2/2] driver core: class.h: remove extern from function prototypes
2023-03-24 10:01 ` [PATCH 2/2] driver core: class.h: remove extern from function prototypes Greg Kroah-Hartman
@ 2023-03-24 13:42 ` Rafael J. Wysocki
0 siblings, 0 replies; 4+ messages in thread
From: Rafael J. Wysocki @ 2023-03-24 13:42 UTC (permalink / raw)
To: Greg Kroah-Hartman; +Cc: linux-kernel, Rafael J. Wysocki
On Fri, Mar 24, 2023 at 11:01 AM Greg Kroah-Hartman
<gregkh@linuxfoundation.org> wrote:
>
> The kernel coding style does not require 'extern' in function prototypes
> in .h files, so remove them from include/linux/device/class.h as they
> are not needed.
>
> Cc: "Rafael J. Wysocki" <rafael@kernel.org>
> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Acked-by: Rafael J. Wysocki <rafael@kernel.org>
> ---
> include/linux/device/class.h | 46 ++++++++++++++++--------------------
> 1 file changed, 20 insertions(+), 26 deletions(-)
>
> diff --git a/include/linux/device/class.h b/include/linux/device/class.h
> index 03d2f99f84c5..1dc7706cb42d 100644
> --- a/include/linux/device/class.h
> +++ b/include/linux/device/class.h
> @@ -82,8 +82,9 @@ struct class_dev_iter {
>
> extern struct kobject *sysfs_dev_block_kobj;
> extern struct kobject *sysfs_dev_char_kobj;
> -extern int __must_check class_register(struct class *class);
> -extern void class_unregister(struct class *class);
> +
> +int __must_check class_register(struct class *class);
> +void class_unregister(struct class *class);
>
> struct class_compat;
> struct class_compat *class_compat_register(const char *name);
> @@ -93,19 +94,15 @@ int class_compat_create_link(struct class_compat *cls, struct device *dev,
> void class_compat_remove_link(struct class_compat *cls, struct device *dev,
> struct device *device_link);
>
> -extern void class_dev_iter_init(struct class_dev_iter *iter,
> - const struct class *class,
> - const struct device *start,
> - const struct device_type *type);
> -extern struct device *class_dev_iter_next(struct class_dev_iter *iter);
> -extern void class_dev_iter_exit(struct class_dev_iter *iter);
> +void class_dev_iter_init(struct class_dev_iter *iter, const struct class *class,
> + const struct device *start, const struct device_type *type);
> +struct device *class_dev_iter_next(struct class_dev_iter *iter);
> +void class_dev_iter_exit(struct class_dev_iter *iter);
>
> -extern int class_for_each_device(const struct class *class, const struct device *start,
> - void *data,
> - int (*fn)(struct device *dev, void *data));
> -extern struct device *class_find_device(const struct class *class,
> - const struct device *start, const void *data,
> - int (*match)(struct device *, const void *));
> +int class_for_each_device(const struct class *class, const struct device *start, void *data,
> + int (*fn)(struct device *dev, void *data));
> +struct device *class_find_device(const struct class *class, const struct device *start,
> + const void *data, int (*match)(struct device *, const void *));
>
> /**
> * class_find_device_by_name - device iterator for locating a particular device
> @@ -191,12 +188,10 @@ struct class_attribute {
> #define CLASS_ATTR_WO(_name) \
> struct class_attribute class_attr_##_name = __ATTR_WO(_name)
>
> -extern int __must_check class_create_file_ns(const struct class *class,
> - const struct class_attribute *attr,
> - const void *ns);
> -extern void class_remove_file_ns(const struct class *class,
> - const struct class_attribute *attr,
> - const void *ns);
> +int __must_check class_create_file_ns(const struct class *class, const struct class_attribute *attr,
> + const void *ns);
> +void class_remove_file_ns(const struct class *class, const struct class_attribute *attr,
> + const void *ns);
>
> static inline int __must_check class_create_file(const struct class *class,
> const struct class_attribute *attr)
> @@ -223,8 +218,7 @@ struct class_attribute_string {
> struct class_attribute_string class_attr_##_name = \
> _CLASS_ATTR_STRING(_name, _mode, _str)
>
> -extern ssize_t show_class_attr_string(struct class *class, struct class_attribute *attr,
> - char *buf);
> +ssize_t show_class_attr_string(struct class *class, struct class_attribute *attr, char *buf);
>
> struct class_interface {
> struct list_head node;
> @@ -234,10 +228,10 @@ struct class_interface {
> void (*remove_dev) (struct device *, struct class_interface *);
> };
>
> -extern int __must_check class_interface_register(struct class_interface *);
> -extern void class_interface_unregister(struct class_interface *);
> +int __must_check class_interface_register(struct class_interface *);
> +void class_interface_unregister(struct class_interface *);
>
> -extern struct class * __must_check class_create(const char *name);
> -extern void class_destroy(struct class *cls);
> +struct class * __must_check class_create(const char *name);
> +void class_destroy(struct class *cls);
>
> #endif /* _DEVICE_CLASS_H_ */
> --
> 2.40.0
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 1/2] driver core: class: use lock_class_key already present in struct subsys_private
2023-03-24 10:01 [PATCH 1/2] driver core: class: use lock_class_key already present in struct subsys_private Greg Kroah-Hartman
2023-03-24 10:01 ` [PATCH 2/2] driver core: class.h: remove extern from function prototypes Greg Kroah-Hartman
@ 2023-03-24 13:42 ` Rafael J. Wysocki
1 sibling, 0 replies; 4+ messages in thread
From: Rafael J. Wysocki @ 2023-03-24 13:42 UTC (permalink / raw)
To: Greg Kroah-Hartman; +Cc: linux-kernel, Rafael J. Wysocki
On Fri, Mar 24, 2023 at 11:01 AM Greg Kroah-Hartman
<gregkh@linuxfoundation.org> wrote:
>
> In commit 37e98d9bedb5 ("driver core: bus: move lock_class_key into
> dynamic structure"), we moved the lock_class_key into the internal
> structure shared by busses and classes, but only used it for buses.
>
> Move the class code to use this structure as it is already present and
> being allocated, instead of the statically allocated on-the-stack
> variable that class_create() was using as part of a macro wrapper around
> the core function call.
>
> Cc: "Rafael J. Wysocki" <rafael@kernel.org>
> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: Rafael J. Wysocki <rafael@kernel.org>
> ---
> drivers/base/class.c | 15 +++++++++------
> include/linux/device/class.h | 36 ++----------------------------------
> 2 files changed, 11 insertions(+), 40 deletions(-)
>
> diff --git a/drivers/base/class.c b/drivers/base/class.c
> index 3d65221b0dcb..dbaeb79ae917 100644
> --- a/drivers/base/class.c
> +++ b/drivers/base/class.c
> @@ -154,9 +154,10 @@ static void class_remove_groups(struct class *cls,
> return sysfs_remove_groups(&cls->p->subsys.kobj, groups);
> }
>
> -int __class_register(struct class *cls, struct lock_class_key *key)
> +int class_register(struct class *cls)
> {
> struct subsys_private *cp;
> + struct lock_class_key *key;
> int error;
>
> pr_debug("device class '%s': registering\n", cls->name);
> @@ -167,6 +168,8 @@ int __class_register(struct class *cls, struct lock_class_key *key)
> klist_init(&cp->klist_devices, klist_class_dev_get, klist_class_dev_put);
> INIT_LIST_HEAD(&cp->interfaces);
> kset_init(&cp->glue_dirs);
> + key = &cp->lock_key;
> + lockdep_register_key(key);
> __mutex_init(&cp->mutex, "subsys mutex", key);
> error = kobject_set_name(&cp->subsys.kobj, "%s", cls->name);
> if (error) {
> @@ -201,7 +204,7 @@ int __class_register(struct class *cls, struct lock_class_key *key)
> cls->p = NULL;
> return error;
> }
> -EXPORT_SYMBOL_GPL(__class_register);
> +EXPORT_SYMBOL_GPL(class_register);
>
> void class_unregister(struct class *cls)
> {
> @@ -218,7 +221,7 @@ static void class_create_release(struct class *cls)
> }
>
> /**
> - * __class_create - create a struct class structure
> + * class_create - create a struct class structure
> * @name: pointer to a string for the name of this class.
> * @key: the lock_class_key for this class; used by mutex lock debugging
> *
> @@ -230,7 +233,7 @@ static void class_create_release(struct class *cls)
> * Note, the pointer created here is to be destroyed when finished by
> * making a call to class_destroy().
> */
> -struct class *__class_create(const char *name, struct lock_class_key *key)
> +struct class *class_create(const char *name)
> {
> struct class *cls;
> int retval;
> @@ -244,7 +247,7 @@ struct class *__class_create(const char *name, struct lock_class_key *key)
> cls->name = name;
> cls->class_release = class_create_release;
>
> - retval = __class_register(cls, key);
> + retval = class_register(cls);
> if (retval)
> goto error;
>
> @@ -254,7 +257,7 @@ struct class *__class_create(const char *name, struct lock_class_key *key)
> kfree(cls);
> return ERR_PTR(retval);
> }
> -EXPORT_SYMBOL_GPL(__class_create);
> +EXPORT_SYMBOL_GPL(class_create);
>
> /**
> * class_destroy - destroys a struct class structure
> diff --git a/include/linux/device/class.h b/include/linux/device/class.h
> index 75c1451fcc63..03d2f99f84c5 100644
> --- a/include/linux/device/class.h
> +++ b/include/linux/device/class.h
> @@ -82,18 +82,9 @@ struct class_dev_iter {
>
> extern struct kobject *sysfs_dev_block_kobj;
> extern struct kobject *sysfs_dev_char_kobj;
> -extern int __must_check __class_register(struct class *class,
> - struct lock_class_key *key);
> +extern int __must_check class_register(struct class *class);
> extern void class_unregister(struct class *class);
>
> -/* This is a #define to keep the compiler from merging different
> - * instances of the __key variable */
> -#define class_register(class) \
> -({ \
> - static struct lock_class_key __key; \
> - __class_register(class, &__key); \
> -})
> -
> struct class_compat;
> struct class_compat *class_compat_register(const char *name);
> void class_compat_unregister(struct class_compat *cls);
> @@ -246,30 +237,7 @@ struct class_interface {
> extern int __must_check class_interface_register(struct class_interface *);
> extern void class_interface_unregister(struct class_interface *);
>
> -extern struct class * __must_check __class_create(const char *name,
> - struct lock_class_key *key);
> +extern struct class * __must_check class_create(const char *name);
> extern void class_destroy(struct class *cls);
>
> -/* This is a #define to keep the compiler from merging different
> - * instances of the __key variable */
> -
> -/**
> - * class_create - create a struct class structure
> - * @name: pointer to a string for the name of this class.
> - *
> - * This is used to create a struct class pointer that can then be used
> - * in calls to device_create().
> - *
> - * Returns &struct class pointer on success, or ERR_PTR() on error.
> - *
> - * Note, the pointer created here is to be destroyed when finished by
> - * making a call to class_destroy().
> - */
> -#define class_create(name) \
> -({ \
> - static struct lock_class_key __key; \
> - __class_create(name, &__key); \
> -})
> -
> -
> #endif /* _DEVICE_CLASS_H_ */
> --
> 2.40.0
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-03-24 13:42 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-03-24 10:01 [PATCH 1/2] driver core: class: use lock_class_key already present in struct subsys_private Greg Kroah-Hartman
2023-03-24 10:01 ` [PATCH 2/2] driver core: class.h: remove extern from function prototypes Greg Kroah-Hartman
2023-03-24 13:42 ` Rafael J. Wysocki
2023-03-24 13:42 ` [PATCH 1/2] driver core: class: use lock_class_key already present in struct subsys_private Rafael J. Wysocki
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox