diff options
author | Andi Kleen <andi@firstfloor.org> | 2008-07-01 12:48:41 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2008-07-22 00:55:02 -0400 |
commit | 4a0b2b4dbe1335b8b9886ba3dc85a145d5d938ed (patch) | |
tree | c2d3a0f86ade5061a1bb9a14aa702323d729fd54 /drivers | |
parent | 36ce6dad6e3cb3f050ed41e0beac0070d2062b25 (diff) |
sysdev: Pass the attribute to the low level sysdev show/store function
This allow to dynamically generate attributes and share show/store
functions between attributes. Right now most attributes are generated
by special macros and lots of duplicated code. With the attribute
passed it's instead possible to attach some data to the attribute
and then use that in shared low level functions to do different things.
I need this for the dynamically generated bank attributes in the x86
machine check code, but it'll allow some further cleanups.
I converted all users in tree to the new show/store prototype. It's a single
huge patch to avoid unbisectable sections.
Runtime tested: x86-32, x86-64
Compiled only: ia64, powerpc
Not compile tested/only grep converted: sh, arm, avr32
Signed-off-by: Andi Kleen <ak@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/base/cpu.c | 10 | ||||
-rw-r--r-- | drivers/base/memory.c | 12 | ||||
-rw-r--r-- | drivers/base/node.c | 15 | ||||
-rw-r--r-- | drivers/base/sys.c | 4 | ||||
-rw-r--r-- | drivers/base/topology.c | 17 | ||||
-rw-r--r-- | drivers/cpuidle/sysfs.c | 10 | ||||
-rw-r--r-- | drivers/xen/balloon.c | 1 |
7 files changed, 46 insertions, 23 deletions
diff --git a/drivers/base/cpu.c b/drivers/base/cpu.c index e38dfed41d80..20537d507909 100644 --- a/drivers/base/cpu.c +++ b/drivers/base/cpu.c | |||
@@ -21,15 +21,16 @@ EXPORT_SYMBOL(cpu_sysdev_class); | |||
21 | static DEFINE_PER_CPU(struct sys_device *, cpu_sys_devices); | 21 | static DEFINE_PER_CPU(struct sys_device *, cpu_sys_devices); |
22 | 22 | ||
23 | #ifdef CONFIG_HOTPLUG_CPU | 23 | #ifdef CONFIG_HOTPLUG_CPU |
24 | static ssize_t show_online(struct sys_device *dev, char *buf) | 24 | static ssize_t show_online(struct sys_device *dev, struct sysdev_attribute *attr, |
25 | char *buf) | ||
25 | { | 26 | { |
26 | struct cpu *cpu = container_of(dev, struct cpu, sysdev); | 27 | struct cpu *cpu = container_of(dev, struct cpu, sysdev); |
27 | 28 | ||
28 | return sprintf(buf, "%u\n", !!cpu_online(cpu->sysdev.id)); | 29 | return sprintf(buf, "%u\n", !!cpu_online(cpu->sysdev.id)); |
29 | } | 30 | } |
30 | 31 | ||
31 | static ssize_t __ref store_online(struct sys_device *dev, const char *buf, | 32 | static ssize_t __ref store_online(struct sys_device *dev, struct sysdev_attribute *attr, |
32 | size_t count) | 33 | const char *buf, size_t count) |
33 | { | 34 | { |
34 | struct cpu *cpu = container_of(dev, struct cpu, sysdev); | 35 | struct cpu *cpu = container_of(dev, struct cpu, sysdev); |
35 | ssize_t ret; | 36 | ssize_t ret; |
@@ -80,7 +81,8 @@ static inline void register_cpu_control(struct cpu *cpu) | |||
80 | #ifdef CONFIG_KEXEC | 81 | #ifdef CONFIG_KEXEC |
81 | #include <linux/kexec.h> | 82 | #include <linux/kexec.h> |
82 | 83 | ||
83 | static ssize_t show_crash_notes(struct sys_device *dev, char *buf) | 84 | static ssize_t show_crash_notes(struct sys_device *dev, struct sysdev_attribute *attr, |
85 | char *buf) | ||
84 | { | 86 | { |
85 | struct cpu *cpu = container_of(dev, struct cpu, sysdev); | 87 | struct cpu *cpu = container_of(dev, struct cpu, sysdev); |
86 | ssize_t rc; | 88 | ssize_t rc; |
diff --git a/drivers/base/memory.c b/drivers/base/memory.c index 937e8258981d..4d4e0e7b6e92 100644 --- a/drivers/base/memory.c +++ b/drivers/base/memory.c | |||
@@ -92,7 +92,8 @@ unregister_memory(struct memory_block *memory, struct mem_section *section) | |||
92 | * uses. | 92 | * uses. |
93 | */ | 93 | */ |
94 | 94 | ||
95 | static ssize_t show_mem_phys_index(struct sys_device *dev, char *buf) | 95 | static ssize_t show_mem_phys_index(struct sys_device *dev, |
96 | struct sysdev_attribute *attr, char *buf) | ||
96 | { | 97 | { |
97 | struct memory_block *mem = | 98 | struct memory_block *mem = |
98 | container_of(dev, struct memory_block, sysdev); | 99 | container_of(dev, struct memory_block, sysdev); |
@@ -102,7 +103,8 @@ static ssize_t show_mem_phys_index(struct sys_device *dev, char *buf) | |||
102 | /* | 103 | /* |
103 | * online, offline, going offline, etc. | 104 | * online, offline, going offline, etc. |
104 | */ | 105 | */ |
105 | static ssize_t show_mem_state(struct sys_device *dev, char *buf) | 106 | static ssize_t show_mem_state(struct sys_device *dev, |
107 | struct sysdev_attribute *attr, char *buf) | ||
106 | { | 108 | { |
107 | struct memory_block *mem = | 109 | struct memory_block *mem = |
108 | container_of(dev, struct memory_block, sysdev); | 110 | container_of(dev, struct memory_block, sysdev); |
@@ -217,7 +219,8 @@ out: | |||
217 | } | 219 | } |
218 | 220 | ||
219 | static ssize_t | 221 | static ssize_t |
220 | store_mem_state(struct sys_device *dev, const char *buf, size_t count) | 222 | store_mem_state(struct sys_device *dev, |
223 | struct sysdev_attribute *attr, const char *buf, size_t count) | ||
221 | { | 224 | { |
222 | struct memory_block *mem; | 225 | struct memory_block *mem; |
223 | unsigned int phys_section_nr; | 226 | unsigned int phys_section_nr; |
@@ -248,7 +251,8 @@ out: | |||
248 | * s.t. if I offline all of these sections I can then | 251 | * s.t. if I offline all of these sections I can then |
249 | * remove the physical device? | 252 | * remove the physical device? |
250 | */ | 253 | */ |
251 | static ssize_t show_phys_device(struct sys_device *dev, char *buf) | 254 | static ssize_t show_phys_device(struct sys_device *dev, |
255 | struct sysdev_attribute *attr, char *buf) | ||
252 | { | 256 | { |
253 | struct memory_block *mem = | 257 | struct memory_block *mem = |
254 | container_of(dev, struct memory_block, sysdev); | 258 | container_of(dev, struct memory_block, sysdev); |
diff --git a/drivers/base/node.c b/drivers/base/node.c index 0f867a083338..5116b78c6325 100644 --- a/drivers/base/node.c +++ b/drivers/base/node.c | |||
@@ -36,11 +36,13 @@ static ssize_t node_read_cpumap(struct sys_device *dev, int type, char *buf) | |||
36 | return len; | 36 | return len; |
37 | } | 37 | } |
38 | 38 | ||
39 | static inline ssize_t node_read_cpumask(struct sys_device *dev, char *buf) | 39 | static inline ssize_t node_read_cpumask(struct sys_device *dev, |
40 | struct sysdev_attribute *attr, char *buf) | ||
40 | { | 41 | { |
41 | return node_read_cpumap(dev, 0, buf); | 42 | return node_read_cpumap(dev, 0, buf); |
42 | } | 43 | } |
43 | static inline ssize_t node_read_cpulist(struct sys_device *dev, char *buf) | 44 | static inline ssize_t node_read_cpulist(struct sys_device *dev, |
45 | struct sysdev_attribute *attr, char *buf) | ||
44 | { | 46 | { |
45 | return node_read_cpumap(dev, 1, buf); | 47 | return node_read_cpumap(dev, 1, buf); |
46 | } | 48 | } |
@@ -49,7 +51,8 @@ static SYSDEV_ATTR(cpumap, S_IRUGO, node_read_cpumask, NULL); | |||
49 | static SYSDEV_ATTR(cpulist, S_IRUGO, node_read_cpulist, NULL); | 51 | static SYSDEV_ATTR(cpulist, S_IRUGO, node_read_cpulist, NULL); |
50 | 52 | ||
51 | #define K(x) ((x) << (PAGE_SHIFT - 10)) | 53 | #define K(x) ((x) << (PAGE_SHIFT - 10)) |
52 | static ssize_t node_read_meminfo(struct sys_device * dev, char * buf) | 54 | static ssize_t node_read_meminfo(struct sys_device * dev, |
55 | struct sysdev_attribute *attr, char * buf) | ||
53 | { | 56 | { |
54 | int n; | 57 | int n; |
55 | int nid = dev->id; | 58 | int nid = dev->id; |
@@ -112,7 +115,8 @@ static ssize_t node_read_meminfo(struct sys_device * dev, char * buf) | |||
112 | #undef K | 115 | #undef K |
113 | static SYSDEV_ATTR(meminfo, S_IRUGO, node_read_meminfo, NULL); | 116 | static SYSDEV_ATTR(meminfo, S_IRUGO, node_read_meminfo, NULL); |
114 | 117 | ||
115 | static ssize_t node_read_numastat(struct sys_device * dev, char * buf) | 118 | static ssize_t node_read_numastat(struct sys_device * dev, |
119 | struct sysdev_attribute *attr, char * buf) | ||
116 | { | 120 | { |
117 | return sprintf(buf, | 121 | return sprintf(buf, |
118 | "numa_hit %lu\n" | 122 | "numa_hit %lu\n" |
@@ -130,7 +134,8 @@ static ssize_t node_read_numastat(struct sys_device * dev, char * buf) | |||
130 | } | 134 | } |
131 | static SYSDEV_ATTR(numastat, S_IRUGO, node_read_numastat, NULL); | 135 | static SYSDEV_ATTR(numastat, S_IRUGO, node_read_numastat, NULL); |
132 | 136 | ||
133 | static ssize_t node_read_distance(struct sys_device * dev, char * buf) | 137 | static ssize_t node_read_distance(struct sys_device * dev, |
138 | struct sysdev_attribute *attr, char * buf) | ||
134 | { | 139 | { |
135 | int nid = dev->id; | 140 | int nid = dev->id; |
136 | int len = 0; | 141 | int len = 0; |
diff --git a/drivers/base/sys.c b/drivers/base/sys.c index 50690d9df248..dc7dace14e1c 100644 --- a/drivers/base/sys.c +++ b/drivers/base/sys.c | |||
@@ -36,7 +36,7 @@ sysdev_show(struct kobject * kobj, struct attribute * attr, char * buffer) | |||
36 | struct sysdev_attribute * sysdev_attr = to_sysdev_attr(attr); | 36 | struct sysdev_attribute * sysdev_attr = to_sysdev_attr(attr); |
37 | 37 | ||
38 | if (sysdev_attr->show) | 38 | if (sysdev_attr->show) |
39 | return sysdev_attr->show(sysdev, buffer); | 39 | return sysdev_attr->show(sysdev, sysdev_attr, buffer); |
40 | return -EIO; | 40 | return -EIO; |
41 | } | 41 | } |
42 | 42 | ||
@@ -49,7 +49,7 @@ sysdev_store(struct kobject * kobj, struct attribute * attr, | |||
49 | struct sysdev_attribute * sysdev_attr = to_sysdev_attr(attr); | 49 | struct sysdev_attribute * sysdev_attr = to_sysdev_attr(attr); |
50 | 50 | ||
51 | if (sysdev_attr->store) | 51 | if (sysdev_attr->store) |
52 | return sysdev_attr->store(sysdev, buffer, count); | 52 | return sysdev_attr->store(sysdev, sysdev_attr, buffer, count); |
53 | return -EIO; | 53 | return -EIO; |
54 | } | 54 | } |
55 | 55 | ||
diff --git a/drivers/base/topology.c b/drivers/base/topology.c index 3f6d9b0a6abe..199cd97e32e6 100644 --- a/drivers/base/topology.c +++ b/drivers/base/topology.c | |||
@@ -34,7 +34,8 @@ | |||
34 | static SYSDEV_ATTR(_name, 0444, show_##_name, NULL) | 34 | static SYSDEV_ATTR(_name, 0444, show_##_name, NULL) |
35 | 35 | ||
36 | #define define_id_show_func(name) \ | 36 | #define define_id_show_func(name) \ |
37 | static ssize_t show_##name(struct sys_device *dev, char *buf) \ | 37 | static ssize_t show_##name(struct sys_device *dev, \ |
38 | struct sysdev_attribute *attr, char *buf) \ | ||
38 | { \ | 39 | { \ |
39 | unsigned int cpu = dev->id; \ | 40 | unsigned int cpu = dev->id; \ |
40 | return sprintf(buf, "%d\n", topology_##name(cpu)); \ | 41 | return sprintf(buf, "%d\n", topology_##name(cpu)); \ |
@@ -59,14 +60,17 @@ static ssize_t show_cpumap(int type, cpumask_t *mask, char *buf) | |||
59 | 60 | ||
60 | #ifdef arch_provides_topology_pointers | 61 | #ifdef arch_provides_topology_pointers |
61 | #define define_siblings_show_map(name) \ | 62 | #define define_siblings_show_map(name) \ |
62 | static ssize_t show_##name(struct sys_device *dev, char *buf) \ | 63 | static ssize_t show_##name(struct sys_device *dev, \ |
64 | struct sysdev_attribute *attr, char *buf) \ | ||
63 | { \ | 65 | { \ |
64 | unsigned int cpu = dev->id; \ | 66 | unsigned int cpu = dev->id; \ |
65 | return show_cpumap(0, &(topology_##name(cpu)), buf); \ | 67 | return show_cpumap(0, &(topology_##name(cpu)), buf); \ |
66 | } | 68 | } |
67 | 69 | ||
68 | #define define_siblings_show_list(name) \ | 70 | #define define_siblings_show_list(name) \ |
69 | static ssize_t show_##name##_list(struct sys_device *dev, char *buf) \ | 71 | static ssize_t show_##name##_list(struct sys_device *dev, \ |
72 | struct sysdev_attribute *attr, \ | ||
73 | char *buf) \ | ||
70 | { \ | 74 | { \ |
71 | unsigned int cpu = dev->id; \ | 75 | unsigned int cpu = dev->id; \ |
72 | return show_cpumap(1, &(topology_##name(cpu)), buf); \ | 76 | return show_cpumap(1, &(topology_##name(cpu)), buf); \ |
@@ -74,7 +78,8 @@ static ssize_t show_##name##_list(struct sys_device *dev, char *buf) \ | |||
74 | 78 | ||
75 | #else | 79 | #else |
76 | #define define_siblings_show_map(name) \ | 80 | #define define_siblings_show_map(name) \ |
77 | static ssize_t show_##name(struct sys_device *dev, char *buf) \ | 81 | static ssize_t show_##name(struct sys_device *dev, \ |
82 | struct sysdev_attribute *attr, char *buf) \ | ||
78 | { \ | 83 | { \ |
79 | unsigned int cpu = dev->id; \ | 84 | unsigned int cpu = dev->id; \ |
80 | cpumask_t mask = topology_##name(cpu); \ | 85 | cpumask_t mask = topology_##name(cpu); \ |
@@ -82,7 +87,9 @@ static ssize_t show_##name(struct sys_device *dev, char *buf) \ | |||
82 | } | 87 | } |
83 | 88 | ||
84 | #define define_siblings_show_list(name) \ | 89 | #define define_siblings_show_list(name) \ |
85 | static ssize_t show_##name##_list(struct sys_device *dev, char *buf) \ | 90 | static ssize_t show_##name##_list(struct sys_device *dev, \ |
91 | struct sysdev_attribute *attr, \ | ||
92 | char *buf) \ | ||
86 | { \ | 93 | { \ |
87 | unsigned int cpu = dev->id; \ | 94 | unsigned int cpu = dev->id; \ |
88 | cpumask_t mask = topology_##name(cpu); \ | 95 | cpumask_t mask = topology_##name(cpu); \ |
diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c index e949618b9be0..31a0e0b455b6 100644 --- a/drivers/cpuidle/sysfs.c +++ b/drivers/cpuidle/sysfs.c | |||
@@ -21,7 +21,8 @@ static int __init cpuidle_sysfs_setup(char *unused) | |||
21 | } | 21 | } |
22 | __setup("cpuidle_sysfs_switch", cpuidle_sysfs_setup); | 22 | __setup("cpuidle_sysfs_switch", cpuidle_sysfs_setup); |
23 | 23 | ||
24 | static ssize_t show_available_governors(struct sys_device *dev, char *buf) | 24 | static ssize_t show_available_governors(struct sys_device *dev, |
25 | struct sysdev_attribute *attr, char *buf) | ||
25 | { | 26 | { |
26 | ssize_t i = 0; | 27 | ssize_t i = 0; |
27 | struct cpuidle_governor *tmp; | 28 | struct cpuidle_governor *tmp; |
@@ -39,7 +40,8 @@ out: | |||
39 | return i; | 40 | return i; |
40 | } | 41 | } |
41 | 42 | ||
42 | static ssize_t show_current_driver(struct sys_device *dev, char *buf) | 43 | static ssize_t show_current_driver(struct sys_device *dev, |
44 | struct sysdev_attribute *attr, char *buf) | ||
43 | { | 45 | { |
44 | ssize_t ret; | 46 | ssize_t ret; |
45 | 47 | ||
@@ -53,7 +55,8 @@ static ssize_t show_current_driver(struct sys_device *dev, char *buf) | |||
53 | return ret; | 55 | return ret; |
54 | } | 56 | } |
55 | 57 | ||
56 | static ssize_t show_current_governor(struct sys_device *dev, char *buf) | 58 | static ssize_t show_current_governor(struct sys_device *dev, |
59 | struct sysdev_attribute *attr, char *buf) | ||
57 | { | 60 | { |
58 | ssize_t ret; | 61 | ssize_t ret; |
59 | 62 | ||
@@ -68,6 +71,7 @@ static ssize_t show_current_governor(struct sys_device *dev, char *buf) | |||
68 | } | 71 | } |
69 | 72 | ||
70 | static ssize_t store_current_governor(struct sys_device *dev, | 73 | static ssize_t store_current_governor(struct sys_device *dev, |
74 | struct sysdev_attribute *attr, | ||
71 | const char *buf, size_t count) | 75 | const char *buf, size_t count) |
72 | { | 76 | { |
73 | char gov_name[CPUIDLE_NAME_LEN]; | 77 | char gov_name[CPUIDLE_NAME_LEN]; |
diff --git a/drivers/xen/balloon.c b/drivers/xen/balloon.c index 591bc29b55f5..d4427cb86979 100644 --- a/drivers/xen/balloon.c +++ b/drivers/xen/balloon.c | |||
@@ -610,6 +610,7 @@ static ssize_t show_target_kb(struct sys_device *dev, char *buf) | |||
610 | } | 610 | } |
611 | 611 | ||
612 | static ssize_t store_target_kb(struct sys_device *dev, | 612 | static ssize_t store_target_kb(struct sys_device *dev, |
613 | struct sysdev_attribute *attr, | ||
613 | const char *buf, | 614 | const char *buf, |
614 | size_t count) | 615 | size_t count) |
615 | { | 616 | { |