mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-15 00:04:15 +08:00
driver core: class: specify the module owner in __class_register()
There's no need to manually have to set the module owner of a class, the compiler should do it automatically for you, so add a module * to the __class_register() function and allow it to set the module owner automatically. This will let us move the module pointer out of struct class eventually, as it should not be embedded in there if we wish for it to be a read-only structure eventually. And, funny story, this module pointer isn't even being used for anything, so while we will keep it around for now, it's not like it even matters. Cc: "Rafael J. Wysocki" <rafael@kernel.org> Link: https://lore.kernel.org/r/20230313181843.1207845-1-gregkh@linuxfoundation.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
64414da25b
commit
4a46ac9d64
@ -154,7 +154,7 @@ 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 module *owner, struct lock_class_key *key)
|
||||
{
|
||||
struct subsys_private *cp;
|
||||
int error;
|
||||
@ -187,6 +187,7 @@ int __class_register(struct class *cls, struct lock_class_key *key)
|
||||
if (error)
|
||||
goto err_out;
|
||||
|
||||
cls->owner = owner;
|
||||
error = class_add_groups(class_get(cls), cls->class_groups);
|
||||
class_put(cls);
|
||||
if (error) {
|
||||
@ -244,10 +245,9 @@ struct class *__class_create(struct module *owner, const char *name,
|
||||
}
|
||||
|
||||
cls->name = name;
|
||||
cls->owner = owner;
|
||||
cls->class_release = class_create_release;
|
||||
|
||||
retval = __class_register(cls, key);
|
||||
retval = __class_register(cls, owner, key);
|
||||
if (retval)
|
||||
goto error;
|
||||
|
||||
|
@ -85,15 +85,16 @@ 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 module *owner,
|
||||
struct lock_class_key *key);
|
||||
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); \
|
||||
#define class_register(class) \
|
||||
({ \
|
||||
static struct lock_class_key __key; \
|
||||
__class_register(class, THIS_MODULE, &__key); \
|
||||
})
|
||||
|
||||
struct class_compat;
|
||||
|
Loading…
Reference in New Issue
Block a user