Skip to content

Commit 38e3fe6

Browse files
t-8chpetrpavlu
authored andcommitted
module: Handle 'struct module_version_attribute' as const
The structure is always read-only due to its placement in the read-only section __modver. Reflect this at its usage sites. Also prepare for the const handling of 'struct module_attribute' itself. Signed-off-by: Thomas Weißschuh <[email protected]> Reviewed-by: Petr Pavlu <[email protected]> Link: https://lore.kernel.org/r/20241216-sysfs-const-attr-module-v1-2-3790b53e0abf@weissschuh.net Signed-off-by: Petr Pavlu <[email protected]>
1 parent 30d4460 commit 38e3fe6

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

include/linux/module.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ extern typeof(name) __mod_device_table__##type##__##name \
275275
#else
276276
#define MODULE_VERSION(_version) \
277277
MODULE_INFO(version, _version); \
278-
static struct module_version_attribute __modver_attr \
278+
static const struct module_version_attribute __modver_attr \
279279
__used __section("__modver") \
280280
__aligned(__alignof__(struct module_version_attribute)) \
281281
= { \

kernel/params.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -860,8 +860,8 @@ static void __init param_sysfs_builtin(void)
860860
ssize_t __modver_version_show(struct module_attribute *mattr,
861861
struct module_kobject *mk, char *buf)
862862
{
863-
struct module_version_attribute *vattr =
864-
container_of(mattr, struct module_version_attribute, mattr);
863+
const struct module_version_attribute *vattr =
864+
container_of_const(mattr, struct module_version_attribute, mattr);
865865

866866
return scnprintf(buf, PAGE_SIZE, "%s\n", vattr->version);
867867
}

0 commit comments

Comments
 (0)