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 <linux@weissschuh.net>
Reviewed-by: Petr Pavlu <petr.pavlu@suse.com>
Link: https://lore.kernel.org/r/20241216-sysfs-const-attr-module-v1-2-3790b53e0abf@weissschuh.net
Signed-off-by: Petr Pavlu <petr.pavlu@suse.com>
This commit is contained in:
Thomas Weißschuh 2024-12-16 18:25:09 +01:00 committed by Petr Pavlu
parent 9930261973
commit cb80af8451
2 changed files with 3 additions and 3 deletions

View File

@ -275,7 +275,7 @@ extern typeof(name) __mod_device_table__##type##__##name \
#else #else
#define MODULE_VERSION(_version) \ #define MODULE_VERSION(_version) \
MODULE_INFO(version, _version); \ MODULE_INFO(version, _version); \
static struct module_version_attribute __modver_attr \ static const struct module_version_attribute __modver_attr \
__used __section("__modver") \ __used __section("__modver") \
__aligned(__alignof__(struct module_version_attribute)) \ __aligned(__alignof__(struct module_version_attribute)) \
= { \ = { \

View File

@ -860,8 +860,8 @@ static void __init param_sysfs_builtin(void)
ssize_t __modver_version_show(struct module_attribute *mattr, ssize_t __modver_version_show(struct module_attribute *mattr,
struct module_kobject *mk, char *buf) struct module_kobject *mk, char *buf)
{ {
struct module_version_attribute *vattr = const struct module_version_attribute *vattr =
container_of(mattr, struct module_version_attribute, mattr); container_of_const(mattr, struct module_version_attribute, mattr);
return scnprintf(buf, PAGE_SIZE, "%s\n", vattr->version); return scnprintf(buf, PAGE_SIZE, "%s\n", vattr->version);
} }