Skip to content

Commit 4befb02

Browse files
kaysieversrustyrussell
authored andcommitted
module: change attr callbacks to take struct module_kobject
This simplifies the next patch, where we have an attribute on a builtin module (ie. module == NULL). Signed-off-by: Kay Sievers <kay.sievers@vrfy.org> Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> (split into 2)
1 parent 66574cc commit 4befb02

3 files changed

Lines changed: 24 additions & 23 deletions

File tree

‎include/linux/module.h‎

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,18 @@ struct modversion_info
4848

4949
struct module;
5050

51+
struct module_kobject {
52+
struct kobject kobj;
53+
struct module *mod;
54+
struct kobject *drivers_dir;
55+
struct module_param_attrs *mp;
56+
};
57+
5158
struct module_attribute {
52-
struct attribute attr;
53-
ssize_t (*show)(struct module_attribute *, struct module *, char *);
54-
ssize_t (*store)(struct module_attribute *, struct module *,
59+
struct attribute attr;
60+
ssize_t (*show)(struct module_attribute *, struct module_kobject *,
61+
char *);
62+
ssize_t (*store)(struct module_attribute *, struct module_kobject *,
5563
const char *, size_t count);
5664
void (*setup)(struct module *, const char *);
5765
int (*test)(struct module *);
@@ -65,15 +73,8 @@ struct module_version_attribute {
6573
} __attribute__ ((__aligned__(sizeof(void *))));
6674

6775
extern ssize_t __modver_version_show(struct module_attribute *,
68-
struct module *, char *);
76+
struct module_kobject *, char *);
6977

70-
struct module_kobject
71-
{
72-
struct kobject kobj;
73-
struct module *mod;
74-
struct kobject *drivers_dir;
75-
struct module_param_attrs *mp;
76-
};
7778

7879
/* These are either module local, or the kernel's dummy ones. */
7980
extern int init_module(void);

‎kernel/module.c‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -545,9 +545,9 @@ static void setup_modinfo_##field(struct module *mod, const char *s) \
545545
mod->field = kstrdup(s, GFP_KERNEL); \
546546
} \
547547
static ssize_t show_modinfo_##field(struct module_attribute *mattr, \
548-
struct module *mod, char *buffer) \
548+
struct module_kobject *mk, char *buffer) \
549549
{ \
550-
return sprintf(buffer, "%s\n", mod->field); \
550+
return sprintf(buffer, "%s\n", mk->mod->field); \
551551
} \
552552
static int modinfo_##field##_exists(struct module *mod) \
553553
{ \
@@ -902,9 +902,9 @@ void symbol_put_addr(void *addr)
902902
EXPORT_SYMBOL_GPL(symbol_put_addr);
903903

904904
static ssize_t show_refcnt(struct module_attribute *mattr,
905-
struct module *mod, char *buffer)
905+
struct module_kobject *mk, char *buffer)
906906
{
907-
return sprintf(buffer, "%u\n", module_refcount(mod));
907+
return sprintf(buffer, "%u\n", module_refcount(mk->mod));
908908
}
909909

910910
static struct module_attribute refcnt = {
@@ -952,11 +952,11 @@ static inline int module_unload_init(struct module *mod)
952952
#endif /* CONFIG_MODULE_UNLOAD */
953953

954954
static ssize_t show_initstate(struct module_attribute *mattr,
955-
struct module *mod, char *buffer)
955+
struct module_kobject *mk, char *buffer)
956956
{
957957
const char *state = "unknown";
958958

959-
switch (mod->state) {
959+
switch (mk->mod->state) {
960960
case MODULE_STATE_LIVE:
961961
state = "live";
962962
break;
@@ -1187,7 +1187,7 @@ struct module_sect_attrs
11871187
};
11881188

11891189
static ssize_t module_sect_show(struct module_attribute *mattr,
1190-
struct module *mod, char *buf)
1190+
struct module_kobject *mk, char *buf)
11911191
{
11921192
struct module_sect_attr *sattr =
11931193
container_of(mattr, struct module_sect_attr, mattr);

‎kernel/params.c‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ struct module_param_attrs
511511
#define to_param_attr(n) container_of(n, struct param_attribute, mattr)
512512

513513
static ssize_t param_attr_show(struct module_attribute *mattr,
514-
struct module *mod, char *buf)
514+
struct module_kobject *mk, char *buf)
515515
{
516516
int count;
517517
struct param_attribute *attribute = to_param_attr(mattr);
@@ -531,7 +531,7 @@ static ssize_t param_attr_show(struct module_attribute *mattr,
531531

532532
/* sysfs always hands a nul-terminated string in buf. We rely on that. */
533533
static ssize_t param_attr_store(struct module_attribute *mattr,
534-
struct module *owner,
534+
struct module_kobject *km,
535535
const char *buf, size_t len)
536536
{
537537
int err;
@@ -807,7 +807,7 @@ static void __init param_sysfs_builtin(void)
807807
}
808808

809809
ssize_t __modver_version_show(struct module_attribute *mattr,
810-
struct module *mod, char *buf)
810+
struct module_kobject *mk, char *buf)
811811
{
812812
struct module_version_attribute *vattr =
813813
container_of(mattr, struct module_version_attribute, mattr);
@@ -852,7 +852,7 @@ static ssize_t module_attr_show(struct kobject *kobj,
852852
if (!attribute->show)
853853
return -EIO;
854854

855-
ret = attribute->show(attribute, mk->mod, buf);
855+
ret = attribute->show(attribute, mk, buf);
856856

857857
return ret;
858858
}
@@ -871,7 +871,7 @@ static ssize_t module_attr_store(struct kobject *kobj,
871871
if (!attribute->store)
872872
return -EIO;
873873

874-
ret = attribute->store(attribute, mk->mod, buf, len);
874+
ret = attribute->store(attribute, mk, buf, len);
875875

876876
return ret;
877877
}

0 commit comments

Comments
 (0)