Skip to contentSkip to conversation

module: make module_ktype structure constant

PATCH In review Thomas Weißschuh 2 participants 2 messages Feb 4, 2023 – Feb 21, 2023 Module support

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 module: make module_ktype structure constant

Since commit ee6d3dd4ed48 ("driver core: make kobj_type constant.") the driver core allows the usage of const struct kobj_type.

Take advantage of this to constify the structure definition to prevent modification at runtime.

---
 include/linux/module.h | 2 +-
 kernel/params.c        | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
include/linux/module.h +1 -1
index 8c5909c0076c..701869049be2 100644
@@ -826,7 +826,7 @@ void *dereference_module_function_descriptor(struct module *mod, void *ptr)
 
 #ifdef CONFIG_SYSFS
 extern struct kset *module_kset;
-extern struct kobj_type module_ktype;
+extern const struct kobj_type module_ktype;
 #endif /* CONFIG_SYSFS */
 
 #define symbol_request(x) try_then_request_module(symbol_get(x), "symbol:" #x)
kernel/params.c +1 -1
index 14d66070757b..049d7078fb21 100644
@@ -947,7 +947,7 @@ static void module_kobj_release(struct kobject *kobj)
 	complete(mk->kobj_completion);
 }
 
-struct kobj_type module_ktype = {
+const struct kobj_type module_ktype = {
 	.release   =	module_kobj_release,
 	.sysfs_ops =	&module_sysfs_ops,
 };

---
base-commit: 0136d86b78522bbd5755f8194c97a987f0586ba5
change-id: 20230204-kobj_type-module-8d15fbee43a5

Best regards,

Signature · 1 line
Thomas Weißschuh <[email protected]>
maintainer
#1 lore raw
Quoted 7 lines · Thomas Weißschuh

Since commit ee6d3dd4ed48 ("driver core: make kobj_type constant.") the driver core allows the usage of const struct kobj_type.

Take advantage of this to constify the structure definition to prevent modification at runtime.

Thanks! Queued onto modules-next.

Luis