Commit 4befb026cf74b52fc7d382142bbfc0e9b6aab5e7

Authored by Kay Sievers
Committed by Rusty Russell
1 parent 66574cc054

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)

Showing 3 changed files with 24 additions and 23 deletions Side-by-side Diff

include/linux/module.h
... ... @@ -48,10 +48,18 @@
48 48  
49 49 struct module;
50 50  
  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 +
51 58 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 *,
55 63 const char *, size_t count);
56 64 void (*setup)(struct module *, const char *);
57 65 int (*test)(struct module *);
58 66  
... ... @@ -65,15 +73,8 @@
65 73 } __attribute__ ((__aligned__(sizeof(void *))));
66 74  
67 75 extern ssize_t __modver_version_show(struct module_attribute *,
68   - struct module *, char *);
  76 + struct module_kobject *, char *);
69 77  
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   -};
77 78  
78 79 /* These are either module local, or the kernel's dummy ones. */
79 80 extern int init_module(void);
... ... @@ -545,9 +545,9 @@
545 545 mod->field = kstrdup(s, GFP_KERNEL); \
546 546 } \
547 547 static ssize_t show_modinfo_##field(struct module_attribute *mattr, \
548   - struct module *mod, char *buffer) \
  548 + struct module_kobject *mk, char *buffer) \
549 549 { \
550   - return sprintf(buffer, "%s\n", mod->field); \
  550 + return sprintf(buffer, "%s\n", mk->mod->field); \
551 551 } \
552 552 static int modinfo_##field##_exists(struct module *mod) \
553 553 { \
554 554  
... ... @@ -902,9 +902,9 @@
902 902 EXPORT_SYMBOL_GPL(symbol_put_addr);
903 903  
904 904 static ssize_t show_refcnt(struct module_attribute *mattr,
905   - struct module *mod, char *buffer)
  905 + struct module_kobject *mk, char *buffer)
906 906 {
907   - return sprintf(buffer, "%u\n", module_refcount(mod));
  907 + return sprintf(buffer, "%u\n", module_refcount(mk->mod));
908 908 }
909 909  
910 910 static struct module_attribute refcnt = {
911 911  
... ... @@ -952,11 +952,11 @@
952 952 #endif /* CONFIG_MODULE_UNLOAD */
953 953  
954 954 static ssize_t show_initstate(struct module_attribute *mattr,
955   - struct module *mod, char *buffer)
  955 + struct module_kobject *mk, char *buffer)
956 956 {
957 957 const char *state = "unknown";
958 958  
959   - switch (mod->state) {
  959 + switch (mk->mod->state) {
960 960 case MODULE_STATE_LIVE:
961 961 state = "live";
962 962 break;
... ... @@ -1187,7 +1187,7 @@
1187 1187 };
1188 1188  
1189 1189 static ssize_t module_sect_show(struct module_attribute *mattr,
1190   - struct module *mod, char *buf)
  1190 + struct module_kobject *mk, char *buf)
1191 1191 {
1192 1192 struct module_sect_attr *sattr =
1193 1193 container_of(mattr, struct module_sect_attr, mattr);
... ... @@ -511,7 +511,7 @@
511 511 #define to_param_attr(n) container_of(n, struct param_attribute, mattr)
512 512  
513 513 static ssize_t param_attr_show(struct module_attribute *mattr,
514   - struct module *mod, char *buf)
  514 + struct module_kobject *mk, char *buf)
515 515 {
516 516 int count;
517 517 struct param_attribute *attribute = to_param_attr(mattr);
... ... @@ -531,7 +531,7 @@
531 531  
532 532 /* sysfs always hands a nul-terminated string in buf. We rely on that. */
533 533 static ssize_t param_attr_store(struct module_attribute *mattr,
534   - struct module *owner,
  534 + struct module_kobject *km,
535 535 const char *buf, size_t len)
536 536 {
537 537 int err;
... ... @@ -807,7 +807,7 @@
807 807 }
808 808  
809 809 ssize_t __modver_version_show(struct module_attribute *mattr,
810   - struct module *mod, char *buf)
  810 + struct module_kobject *mk, char *buf)
811 811 {
812 812 struct module_version_attribute *vattr =
813 813 container_of(mattr, struct module_version_attribute, mattr);
... ... @@ -852,7 +852,7 @@
852 852 if (!attribute->show)
853 853 return -EIO;
854 854  
855   - ret = attribute->show(attribute, mk->mod, buf);
  855 + ret = attribute->show(attribute, mk, buf);
856 856  
857 857 return ret;
858 858 }
... ... @@ -871,7 +871,7 @@
871 871 if (!attribute->store)
872 872 return -EIO;
873 873  
874   - ret = attribute->store(attribute, mk->mod, buf, len);
  874 + ret = attribute->store(attribute, mk, buf, len);
875 875  
876 876 return ret;
877 877 }