driver core: class: use lock_class_key already present in struct subsys_private

In commit 37e98d9bed ("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.

Reviewed-by: Rafael J. Wysocki <rafael@kernel.org>
Link: https://lore.kernel.org/r/20230324100132.1633647-1-gregkh@linuxfoundation.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
Greg Kroah-Hartman 2023-03-24 11:01:31 +01:00
Родитель 5b9ff0ba11
Коммит dcfbb67e48
2 изменённых файлов: 11 добавлений и 40 удалений

Просмотреть файл

@ -154,9 +154,10 @@ static void class_remove_groups(struct class *cls,
return sysfs_remove_groups(&cls->p->subsys.kobj, groups); 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 subsys_private *cp;
struct lock_class_key *key;
int error; int error;
pr_debug("device class '%s': registering\n", cls->name); 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); klist_init(&cp->klist_devices, klist_class_dev_get, klist_class_dev_put);
INIT_LIST_HEAD(&cp->interfaces); INIT_LIST_HEAD(&cp->interfaces);
kset_init(&cp->glue_dirs); kset_init(&cp->glue_dirs);
key = &cp->lock_key;
lockdep_register_key(key);
__mutex_init(&cp->mutex, "subsys mutex", key); __mutex_init(&cp->mutex, "subsys mutex", key);
error = kobject_set_name(&cp->subsys.kobj, "%s", cls->name); error = kobject_set_name(&cp->subsys.kobj, "%s", cls->name);
if (error) { if (error) {
@ -201,7 +204,7 @@ err_out:
cls->p = NULL; cls->p = NULL;
return error; return error;
} }
EXPORT_SYMBOL_GPL(__class_register); EXPORT_SYMBOL_GPL(class_register);
void class_unregister(struct class *cls) 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. * @name: pointer to a string for the name of this class.
* @key: the lock_class_key for this class; used by mutex lock debugging * @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 * Note, the pointer created here is to be destroyed when finished by
* making a call to class_destroy(). * 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; struct class *cls;
int retval; int retval;
@ -244,7 +247,7 @@ struct class *__class_create(const char *name, struct lock_class_key *key)
cls->name = name; cls->name = name;
cls->class_release = class_create_release; cls->class_release = class_create_release;
retval = __class_register(cls, key); retval = class_register(cls);
if (retval) if (retval)
goto error; goto error;
@ -254,7 +257,7 @@ error:
kfree(cls); kfree(cls);
return ERR_PTR(retval); return ERR_PTR(retval);
} }
EXPORT_SYMBOL_GPL(__class_create); EXPORT_SYMBOL_GPL(class_create);
/** /**
* class_destroy - destroys a struct class structure * class_destroy - destroys a struct class structure

Просмотреть файл

@ -82,18 +82,9 @@ struct class_dev_iter {
extern struct kobject *sysfs_dev_block_kobj; extern struct kobject *sysfs_dev_block_kobj;
extern struct kobject *sysfs_dev_char_kobj; extern struct kobject *sysfs_dev_char_kobj;
extern int __must_check __class_register(struct class *class, extern int __must_check class_register(struct class *class);
struct lock_class_key *key);
extern void class_unregister(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;
struct class_compat *class_compat_register(const char *name); struct class_compat *class_compat_register(const char *name);
void class_compat_unregister(struct class_compat *cls); 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 int __must_check class_interface_register(struct class_interface *);
extern void class_interface_unregister(struct class_interface *); extern void class_interface_unregister(struct class_interface *);
extern struct class * __must_check __class_create(const char *name, extern struct class * __must_check class_create(const char *name);
struct lock_class_key *key);
extern void class_destroy(struct class *cls); 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_ */ #endif /* _DEVICE_CLASS_H_ */