mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
synced 2025-01-15 02:05:33 +00:00
module: Constify 'struct module_attribute'
These structs are never modified, move them to read-only memory. This makes the API clearer and also prepares for the constification of 'struct attribute' itself. While at it, also constify 'modinfo_attrs_count'. 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-3-3790b53e0abf@weissschuh.net Signed-off-by: Petr Pavlu <petr.pavlu@suse.com>
This commit is contained in:
parent
cb80af8451
commit
25aa761160
@ -52,9 +52,9 @@ struct module_kobject {
|
|||||||
|
|
||||||
struct module_attribute {
|
struct module_attribute {
|
||||||
struct attribute attr;
|
struct attribute attr;
|
||||||
ssize_t (*show)(struct module_attribute *, struct module_kobject *,
|
ssize_t (*show)(const struct module_attribute *, struct module_kobject *,
|
||||||
char *);
|
char *);
|
||||||
ssize_t (*store)(struct module_attribute *, struct module_kobject *,
|
ssize_t (*store)(const struct module_attribute *, struct module_kobject *,
|
||||||
const char *, size_t count);
|
const char *, size_t count);
|
||||||
void (*setup)(struct module *, const char *);
|
void (*setup)(struct module *, const char *);
|
||||||
int (*test)(struct module *);
|
int (*test)(struct module *);
|
||||||
@ -67,10 +67,10 @@ struct module_version_attribute {
|
|||||||
const char *version;
|
const char *version;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern ssize_t __modver_version_show(struct module_attribute *,
|
extern ssize_t __modver_version_show(const struct module_attribute *,
|
||||||
struct module_kobject *, char *);
|
struct module_kobject *, char *);
|
||||||
|
|
||||||
extern struct module_attribute module_uevent;
|
extern const struct module_attribute module_uevent;
|
||||||
|
|
||||||
/* These are either module local, or the kernel's dummy ones. */
|
/* These are either module local, or the kernel's dummy ones. */
|
||||||
extern int init_module(void);
|
extern int init_module(void);
|
||||||
|
@ -47,8 +47,8 @@ struct kernel_symbol {
|
|||||||
extern struct mutex module_mutex;
|
extern struct mutex module_mutex;
|
||||||
extern struct list_head modules;
|
extern struct list_head modules;
|
||||||
|
|
||||||
extern struct module_attribute *modinfo_attrs[];
|
extern const struct module_attribute *const modinfo_attrs[];
|
||||||
extern size_t modinfo_attrs_count;
|
extern const size_t modinfo_attrs_count;
|
||||||
|
|
||||||
/* Provided by the linker */
|
/* Provided by the linker */
|
||||||
extern const struct kernel_symbol __start___ksymtab[];
|
extern const struct kernel_symbol __start___ksymtab[];
|
||||||
|
@ -538,7 +538,7 @@ static void setup_modinfo_##field(struct module *mod, const char *s) \
|
|||||||
{ \
|
{ \
|
||||||
mod->field = kstrdup(s, GFP_KERNEL); \
|
mod->field = kstrdup(s, GFP_KERNEL); \
|
||||||
} \
|
} \
|
||||||
static ssize_t show_modinfo_##field(struct module_attribute *mattr, \
|
static ssize_t show_modinfo_##field(const struct module_attribute *mattr, \
|
||||||
struct module_kobject *mk, char *buffer) \
|
struct module_kobject *mk, char *buffer) \
|
||||||
{ \
|
{ \
|
||||||
return scnprintf(buffer, PAGE_SIZE, "%s\n", mk->mod->field); \
|
return scnprintf(buffer, PAGE_SIZE, "%s\n", mk->mod->field); \
|
||||||
@ -552,7 +552,7 @@ static void free_modinfo_##field(struct module *mod) \
|
|||||||
kfree(mod->field); \
|
kfree(mod->field); \
|
||||||
mod->field = NULL; \
|
mod->field = NULL; \
|
||||||
} \
|
} \
|
||||||
static struct module_attribute modinfo_##field = { \
|
static const struct module_attribute modinfo_##field = { \
|
||||||
.attr = { .name = __stringify(field), .mode = 0444 }, \
|
.attr = { .name = __stringify(field), .mode = 0444 }, \
|
||||||
.show = show_modinfo_##field, \
|
.show = show_modinfo_##field, \
|
||||||
.setup = setup_modinfo_##field, \
|
.setup = setup_modinfo_##field, \
|
||||||
@ -842,13 +842,13 @@ void symbol_put_addr(void *addr)
|
|||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(symbol_put_addr);
|
EXPORT_SYMBOL_GPL(symbol_put_addr);
|
||||||
|
|
||||||
static ssize_t show_refcnt(struct module_attribute *mattr,
|
static ssize_t show_refcnt(const struct module_attribute *mattr,
|
||||||
struct module_kobject *mk, char *buffer)
|
struct module_kobject *mk, char *buffer)
|
||||||
{
|
{
|
||||||
return sprintf(buffer, "%i\n", module_refcount(mk->mod));
|
return sprintf(buffer, "%i\n", module_refcount(mk->mod));
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct module_attribute modinfo_refcnt =
|
static const struct module_attribute modinfo_refcnt =
|
||||||
__ATTR(refcnt, 0444, show_refcnt, NULL);
|
__ATTR(refcnt, 0444, show_refcnt, NULL);
|
||||||
|
|
||||||
void __module_get(struct module *module)
|
void __module_get(struct module *module)
|
||||||
@ -917,7 +917,7 @@ size_t module_flags_taint(unsigned long taints, char *buf)
|
|||||||
return l;
|
return l;
|
||||||
}
|
}
|
||||||
|
|
||||||
static ssize_t show_initstate(struct module_attribute *mattr,
|
static ssize_t show_initstate(const struct module_attribute *mattr,
|
||||||
struct module_kobject *mk, char *buffer)
|
struct module_kobject *mk, char *buffer)
|
||||||
{
|
{
|
||||||
const char *state = "unknown";
|
const char *state = "unknown";
|
||||||
@ -938,10 +938,10 @@ static ssize_t show_initstate(struct module_attribute *mattr,
|
|||||||
return sprintf(buffer, "%s\n", state);
|
return sprintf(buffer, "%s\n", state);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct module_attribute modinfo_initstate =
|
static const struct module_attribute modinfo_initstate =
|
||||||
__ATTR(initstate, 0444, show_initstate, NULL);
|
__ATTR(initstate, 0444, show_initstate, NULL);
|
||||||
|
|
||||||
static ssize_t store_uevent(struct module_attribute *mattr,
|
static ssize_t store_uevent(const struct module_attribute *mattr,
|
||||||
struct module_kobject *mk,
|
struct module_kobject *mk,
|
||||||
const char *buffer, size_t count)
|
const char *buffer, size_t count)
|
||||||
{
|
{
|
||||||
@ -951,10 +951,10 @@ static ssize_t store_uevent(struct module_attribute *mattr,
|
|||||||
return rc ? rc : count;
|
return rc ? rc : count;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct module_attribute module_uevent =
|
const struct module_attribute module_uevent =
|
||||||
__ATTR(uevent, 0200, NULL, store_uevent);
|
__ATTR(uevent, 0200, NULL, store_uevent);
|
||||||
|
|
||||||
static ssize_t show_coresize(struct module_attribute *mattr,
|
static ssize_t show_coresize(const struct module_attribute *mattr,
|
||||||
struct module_kobject *mk, char *buffer)
|
struct module_kobject *mk, char *buffer)
|
||||||
{
|
{
|
||||||
unsigned int size = mk->mod->mem[MOD_TEXT].size;
|
unsigned int size = mk->mod->mem[MOD_TEXT].size;
|
||||||
@ -966,11 +966,11 @@ static ssize_t show_coresize(struct module_attribute *mattr,
|
|||||||
return sprintf(buffer, "%u\n", size);
|
return sprintf(buffer, "%u\n", size);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct module_attribute modinfo_coresize =
|
static const struct module_attribute modinfo_coresize =
|
||||||
__ATTR(coresize, 0444, show_coresize, NULL);
|
__ATTR(coresize, 0444, show_coresize, NULL);
|
||||||
|
|
||||||
#ifdef CONFIG_ARCH_WANTS_MODULES_DATA_IN_VMALLOC
|
#ifdef CONFIG_ARCH_WANTS_MODULES_DATA_IN_VMALLOC
|
||||||
static ssize_t show_datasize(struct module_attribute *mattr,
|
static ssize_t show_datasize(const struct module_attribute *mattr,
|
||||||
struct module_kobject *mk, char *buffer)
|
struct module_kobject *mk, char *buffer)
|
||||||
{
|
{
|
||||||
unsigned int size = 0;
|
unsigned int size = 0;
|
||||||
@ -980,11 +980,11 @@ static ssize_t show_datasize(struct module_attribute *mattr,
|
|||||||
return sprintf(buffer, "%u\n", size);
|
return sprintf(buffer, "%u\n", size);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct module_attribute modinfo_datasize =
|
static const struct module_attribute modinfo_datasize =
|
||||||
__ATTR(datasize, 0444, show_datasize, NULL);
|
__ATTR(datasize, 0444, show_datasize, NULL);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static ssize_t show_initsize(struct module_attribute *mattr,
|
static ssize_t show_initsize(const struct module_attribute *mattr,
|
||||||
struct module_kobject *mk, char *buffer)
|
struct module_kobject *mk, char *buffer)
|
||||||
{
|
{
|
||||||
unsigned int size = 0;
|
unsigned int size = 0;
|
||||||
@ -994,10 +994,10 @@ static ssize_t show_initsize(struct module_attribute *mattr,
|
|||||||
return sprintf(buffer, "%u\n", size);
|
return sprintf(buffer, "%u\n", size);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct module_attribute modinfo_initsize =
|
static const struct module_attribute modinfo_initsize =
|
||||||
__ATTR(initsize, 0444, show_initsize, NULL);
|
__ATTR(initsize, 0444, show_initsize, NULL);
|
||||||
|
|
||||||
static ssize_t show_taint(struct module_attribute *mattr,
|
static ssize_t show_taint(const struct module_attribute *mattr,
|
||||||
struct module_kobject *mk, char *buffer)
|
struct module_kobject *mk, char *buffer)
|
||||||
{
|
{
|
||||||
size_t l;
|
size_t l;
|
||||||
@ -1007,10 +1007,10 @@ static ssize_t show_taint(struct module_attribute *mattr,
|
|||||||
return l;
|
return l;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct module_attribute modinfo_taint =
|
static const struct module_attribute modinfo_taint =
|
||||||
__ATTR(taint, 0444, show_taint, NULL);
|
__ATTR(taint, 0444, show_taint, NULL);
|
||||||
|
|
||||||
struct module_attribute *modinfo_attrs[] = {
|
const struct module_attribute *const modinfo_attrs[] = {
|
||||||
&module_uevent,
|
&module_uevent,
|
||||||
&modinfo_version,
|
&modinfo_version,
|
||||||
&modinfo_srcversion,
|
&modinfo_srcversion,
|
||||||
@ -1027,7 +1027,7 @@ struct module_attribute *modinfo_attrs[] = {
|
|||||||
NULL,
|
NULL,
|
||||||
};
|
};
|
||||||
|
|
||||||
size_t modinfo_attrs_count = ARRAY_SIZE(modinfo_attrs);
|
const size_t modinfo_attrs_count = ARRAY_SIZE(modinfo_attrs);
|
||||||
|
|
||||||
static const char vermagic[] = VERMAGIC_STRING;
|
static const char vermagic[] = VERMAGIC_STRING;
|
||||||
|
|
||||||
@ -1681,7 +1681,7 @@ static void module_license_taint_check(struct module *mod, const char *license)
|
|||||||
|
|
||||||
static void setup_modinfo(struct module *mod, struct load_info *info)
|
static void setup_modinfo(struct module *mod, struct load_info *info)
|
||||||
{
|
{
|
||||||
struct module_attribute *attr;
|
const struct module_attribute *attr;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; (attr = modinfo_attrs[i]); i++) {
|
for (i = 0; (attr = modinfo_attrs[i]); i++) {
|
||||||
@ -1692,7 +1692,7 @@ static void setup_modinfo(struct module *mod, struct load_info *info)
|
|||||||
|
|
||||||
static void free_modinfo(struct module *mod)
|
static void free_modinfo(struct module *mod)
|
||||||
{
|
{
|
||||||
struct module_attribute *attr;
|
const struct module_attribute *attr;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; (attr = modinfo_attrs[i]); i++) {
|
for (i = 0; (attr = modinfo_attrs[i]); i++) {
|
||||||
|
@ -275,7 +275,7 @@ static int add_usage_links(struct module *mod)
|
|||||||
|
|
||||||
static void module_remove_modinfo_attrs(struct module *mod, int end)
|
static void module_remove_modinfo_attrs(struct module *mod, int end)
|
||||||
{
|
{
|
||||||
struct module_attribute *attr;
|
const struct module_attribute *attr;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; (attr = &mod->modinfo_attrs[i]); i++) {
|
for (i = 0; (attr = &mod->modinfo_attrs[i]); i++) {
|
||||||
@ -293,7 +293,7 @@ static void module_remove_modinfo_attrs(struct module *mod, int end)
|
|||||||
|
|
||||||
static int module_add_modinfo_attrs(struct module *mod)
|
static int module_add_modinfo_attrs(struct module *mod)
|
||||||
{
|
{
|
||||||
struct module_attribute *attr;
|
const struct module_attribute *attr;
|
||||||
struct module_attribute *temp_attr;
|
struct module_attribute *temp_attr;
|
||||||
int error = 0;
|
int error = 0;
|
||||||
int i;
|
int i;
|
||||||
|
@ -538,7 +538,7 @@ const struct kernel_param_ops param_ops_string = {
|
|||||||
EXPORT_SYMBOL(param_ops_string);
|
EXPORT_SYMBOL(param_ops_string);
|
||||||
|
|
||||||
/* sysfs output in /sys/modules/XYZ/parameters/ */
|
/* sysfs output in /sys/modules/XYZ/parameters/ */
|
||||||
#define to_module_attr(n) container_of(n, struct module_attribute, attr)
|
#define to_module_attr(n) container_of_const(n, struct module_attribute, attr)
|
||||||
#define to_module_kobject(n) container_of(n, struct module_kobject, kobj)
|
#define to_module_kobject(n) container_of(n, struct module_kobject, kobj)
|
||||||
|
|
||||||
struct param_attribute
|
struct param_attribute
|
||||||
@ -557,7 +557,7 @@ struct module_param_attrs
|
|||||||
#ifdef CONFIG_SYSFS
|
#ifdef CONFIG_SYSFS
|
||||||
#define to_param_attr(n) container_of_const(n, struct param_attribute, mattr)
|
#define to_param_attr(n) container_of_const(n, struct param_attribute, mattr)
|
||||||
|
|
||||||
static ssize_t param_attr_show(struct module_attribute *mattr,
|
static ssize_t param_attr_show(const struct module_attribute *mattr,
|
||||||
struct module_kobject *mk, char *buf)
|
struct module_kobject *mk, char *buf)
|
||||||
{
|
{
|
||||||
int count;
|
int count;
|
||||||
@ -573,7 +573,7 @@ static ssize_t param_attr_show(struct module_attribute *mattr,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* sysfs always hands a nul-terminated string in buf. We rely on that. */
|
/* sysfs always hands a nul-terminated string in buf. We rely on that. */
|
||||||
static ssize_t param_attr_store(struct module_attribute *mattr,
|
static ssize_t param_attr_store(const struct module_attribute *mattr,
|
||||||
struct module_kobject *mk,
|
struct module_kobject *mk,
|
||||||
const char *buf, size_t len)
|
const char *buf, size_t len)
|
||||||
{
|
{
|
||||||
@ -857,7 +857,7 @@ static void __init param_sysfs_builtin(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t __modver_version_show(struct module_attribute *mattr,
|
ssize_t __modver_version_show(const struct module_attribute *mattr,
|
||||||
struct module_kobject *mk, char *buf)
|
struct module_kobject *mk, char *buf)
|
||||||
{
|
{
|
||||||
const struct module_version_attribute *vattr =
|
const struct module_version_attribute *vattr =
|
||||||
@ -892,7 +892,7 @@ static ssize_t module_attr_show(struct kobject *kobj,
|
|||||||
struct attribute *attr,
|
struct attribute *attr,
|
||||||
char *buf)
|
char *buf)
|
||||||
{
|
{
|
||||||
struct module_attribute *attribute;
|
const struct module_attribute *attribute;
|
||||||
struct module_kobject *mk;
|
struct module_kobject *mk;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
@ -911,7 +911,7 @@ static ssize_t module_attr_store(struct kobject *kobj,
|
|||||||
struct attribute *attr,
|
struct attribute *attr,
|
||||||
const char *buf, size_t len)
|
const char *buf, size_t len)
|
||||||
{
|
{
|
||||||
struct module_attribute *attribute;
|
const struct module_attribute *attribute;
|
||||||
struct module_kobject *mk;
|
struct module_kobject *mk;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user