public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 01/12] driver core: class: specify the module owner in __class_register()
@ 2023-03-13 18:18 Greg Kroah-Hartman
  2023-03-13 18:18 ` [PATCH 02/12] drivers: remove struct module * setting from struct class Greg Kroah-Hartman
                   ` (10 more replies)
  0 siblings, 11 replies; 16+ messages in thread
From: Greg Kroah-Hartman @ 2023-03-13 18:18 UTC (permalink / raw)
  To: linux-kernel; +Cc: rafael, Greg Kroah-Hartman

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>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 drivers/base/class.c         | 6 +++---
 include/linux/device/class.h | 9 +++++----
 2 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/drivers/base/class.c b/drivers/base/class.c
index 5983eead8391..90dc5788957a 100644
--- a/drivers/base/class.c
+++ b/drivers/base/class.c
@@ -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;
 
diff --git a/include/linux/device/class.h b/include/linux/device/class.h
index 42cc3fb44a84..d1ba4ee235dc 100644
--- a/include/linux/device/class.h
+++ b/include/linux/device/class.h
@@ -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;
-- 
2.39.2


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

end of thread, other threads:[~2023-03-15  8:35 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-03-13 18:18 [PATCH 01/12] driver core: class: specify the module owner in __class_register() Greg Kroah-Hartman
2023-03-13 18:18 ` [PATCH 02/12] drivers: remove struct module * setting from struct class Greg Kroah-Hartman
2023-03-13 18:18 ` [PATCH 03/12] driver core: class: remove struct module owner out of " Greg Kroah-Hartman
2023-03-13 18:18 ` [PATCH 04/12] driver core: class: remove module * from class_create() Greg Kroah-Hartman
2023-03-15  8:34   ` Benjamin Tissoires
2023-03-13 18:18 ` [PATCH 05/12] driver core: class: make class_dev_iter_init() options const Greg Kroah-Hartman
2023-03-13 18:18 ` [PATCH 06/12] driver core: class: make class_for_each_device() " Greg Kroah-Hartman
2023-03-13 18:18 ` [PATCH 07/12] driver core: class: make class_find_device*() " Greg Kroah-Hartman
2023-03-13 18:18 ` [PATCH 08/12] driver core: class: make class_create/remove_file*() " Greg Kroah-Hartman
2023-03-13 18:18 ` [PATCH 09/12] driver core: device: make device_destroy() take a const class * Greg Kroah-Hartman
2023-03-13 18:18 ` [PATCH 10/12] tpm: fix up the tpm_class shutdown_pre pointer when created Greg Kroah-Hartman
2023-03-14 11:09   ` Jarkko Sakkinen
2023-03-14 12:53     ` Greg Kroah-Hartman
2023-03-14 12:57       ` Jarkko Sakkinen
2023-03-13 18:18 ` [PATCH 11/12] driver core: device: mark struct class in struct device as constant Greg Kroah-Hartman
2023-03-13 18:18 ` [PATCH 12/12] driver core: device: make device_create*() take a const struct class * Greg Kroah-Hartman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox