diff options
author | Dmitry Torokhov <dmitry.torokhov@gmail.com> | 2017-02-14 15:24:09 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2017-03-17 02:10:49 -0400 |
commit | 87e715deb8e24bf1a6a9a1babaf465c28c93889c (patch) | |
tree | 301f21d1a648dc9a84c1eb65df4c2e77fc79cb4a /drivers/zorro | |
parent | a553910fbaafbd7c18823c0f1e5dcc2d12c9fd2a (diff) |
zorro: stop creating attributes by hand
Instead of creating attributes one by one, define attribute_group array
and attach it to bus->dev_groups, so that all needed attributes are created
automatically when a new device is registered on the bus.
Also switch to using standard DEVICE_ATTR_RO() macros.
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/zorro')
-rw-r--r-- | drivers/zorro/zorro-driver.c | 15 | ||||
-rw-r--r-- | drivers/zorro/zorro-sysfs.c | 76 | ||||
-rw-r--r-- | drivers/zorro/zorro.c | 3 | ||||
-rw-r--r-- | drivers/zorro/zorro.h | 3 |
4 files changed, 50 insertions, 47 deletions
diff --git a/drivers/zorro/zorro-driver.c b/drivers/zorro/zorro-driver.c index eacae1434b73..fa23b7366b98 100644 --- a/drivers/zorro/zorro-driver.c +++ b/drivers/zorro/zorro-driver.c | |||
@@ -14,6 +14,8 @@ | |||
14 | #include <linux/module.h> | 14 | #include <linux/module.h> |
15 | #include <linux/zorro.h> | 15 | #include <linux/zorro.h> |
16 | 16 | ||
17 | #include "zorro.h" | ||
18 | |||
17 | 19 | ||
18 | /** | 20 | /** |
19 | * zorro_match_device - Tell if a Zorro device structure has a matching | 21 | * zorro_match_device - Tell if a Zorro device structure has a matching |
@@ -161,12 +163,13 @@ static int zorro_uevent(struct device *dev, struct kobj_uevent_env *env) | |||
161 | } | 163 | } |
162 | 164 | ||
163 | struct bus_type zorro_bus_type = { | 165 | struct bus_type zorro_bus_type = { |
164 | .name = "zorro", | 166 | .name = "zorro", |
165 | .dev_name = "zorro", | 167 | .dev_name = "zorro", |
166 | .match = zorro_bus_match, | 168 | .dev_groups = zorro_device_attribute_groups, |
167 | .uevent = zorro_uevent, | 169 | .match = zorro_bus_match, |
168 | .probe = zorro_device_probe, | 170 | .uevent = zorro_uevent, |
169 | .remove = zorro_device_remove, | 171 | .probe = zorro_device_probe, |
172 | .remove = zorro_device_remove, | ||
170 | }; | 173 | }; |
171 | EXPORT_SYMBOL(zorro_bus_type); | 174 | EXPORT_SYMBOL(zorro_bus_type); |
172 | 175 | ||
diff --git a/drivers/zorro/zorro-sysfs.c b/drivers/zorro/zorro-sysfs.c index 9282dbf5abdb..3d34dba9bb2d 100644 --- a/drivers/zorro/zorro-sysfs.c +++ b/drivers/zorro/zorro-sysfs.c | |||
@@ -23,33 +23,33 @@ | |||
23 | 23 | ||
24 | /* show configuration fields */ | 24 | /* show configuration fields */ |
25 | #define zorro_config_attr(name, field, format_string) \ | 25 | #define zorro_config_attr(name, field, format_string) \ |
26 | static ssize_t \ | 26 | static ssize_t name##_show(struct device *dev, \ |
27 | show_##name(struct device *dev, struct device_attribute *attr, char *buf) \ | 27 | struct device_attribute *attr, char *buf) \ |
28 | { \ | 28 | { \ |
29 | struct zorro_dev *z; \ | 29 | struct zorro_dev *z; \ |
30 | \ | 30 | \ |
31 | z = to_zorro_dev(dev); \ | 31 | z = to_zorro_dev(dev); \ |
32 | return sprintf(buf, format_string, z->field); \ | 32 | return sprintf(buf, format_string, z->field); \ |
33 | } \ | 33 | } \ |
34 | static DEVICE_ATTR(name, S_IRUGO, show_##name, NULL); | 34 | static DEVICE_ATTR_RO(name); |
35 | 35 | ||
36 | zorro_config_attr(id, id, "0x%08x\n"); | 36 | zorro_config_attr(id, id, "0x%08x\n"); |
37 | zorro_config_attr(type, rom.er_Type, "0x%02x\n"); | 37 | zorro_config_attr(type, rom.er_Type, "0x%02x\n"); |
38 | zorro_config_attr(slotaddr, slotaddr, "0x%04x\n"); | 38 | zorro_config_attr(slotaddr, slotaddr, "0x%04x\n"); |
39 | zorro_config_attr(slotsize, slotsize, "0x%04x\n"); | 39 | zorro_config_attr(slotsize, slotsize, "0x%04x\n"); |
40 | 40 | ||
41 | static ssize_t | 41 | static ssize_t serial_show(struct device *dev, struct device_attribute *attr, |
42 | show_serial(struct device *dev, struct device_attribute *attr, char *buf) | 42 | char *buf) |
43 | { | 43 | { |
44 | struct zorro_dev *z; | 44 | struct zorro_dev *z; |
45 | 45 | ||
46 | z = to_zorro_dev(dev); | 46 | z = to_zorro_dev(dev); |
47 | return sprintf(buf, "0x%08x\n", be32_to_cpu(z->rom.er_SerialNumber)); | 47 | return sprintf(buf, "0x%08x\n", be32_to_cpu(z->rom.er_SerialNumber)); |
48 | } | 48 | } |
49 | static DEVICE_ATTR_RO(serial); | ||
49 | 50 | ||
50 | static DEVICE_ATTR(serial, S_IRUGO, show_serial, NULL); | 51 | static ssize_t resource_show(struct device *dev, struct device_attribute *attr, |
51 | 52 | char *buf) | |
52 | static ssize_t zorro_show_resource(struct device *dev, struct device_attribute *attr, char *buf) | ||
53 | { | 53 | { |
54 | struct zorro_dev *z = to_zorro_dev(dev); | 54 | struct zorro_dev *z = to_zorro_dev(dev); |
55 | 55 | ||
@@ -58,8 +58,27 @@ static ssize_t zorro_show_resource(struct device *dev, struct device_attribute * | |||
58 | (unsigned long)zorro_resource_end(z), | 58 | (unsigned long)zorro_resource_end(z), |
59 | zorro_resource_flags(z)); | 59 | zorro_resource_flags(z)); |
60 | } | 60 | } |
61 | static DEVICE_ATTR_RO(resource); | ||
62 | |||
63 | static ssize_t modalias_show(struct device *dev, struct device_attribute *attr, | ||
64 | char *buf) | ||
65 | { | ||
66 | struct zorro_dev *z = to_zorro_dev(dev); | ||
61 | 67 | ||
62 | static DEVICE_ATTR(resource, S_IRUGO, zorro_show_resource, NULL); | 68 | return sprintf(buf, ZORRO_DEVICE_MODALIAS_FMT "\n", z->id); |
69 | } | ||
70 | static DEVICE_ATTR_RO(modalias); | ||
71 | |||
72 | static struct attribute *zorro_device_attrs[] = { | ||
73 | &dev_attr_id.attr, | ||
74 | &dev_attr_type.attr, | ||
75 | &dev_attr_serial.attr, | ||
76 | &dev_attr_slotaddr.attr, | ||
77 | &dev_attr_slotsize.attr, | ||
78 | &dev_attr_resource.attr, | ||
79 | &dev_attr_modalias.attr, | ||
80 | NULL | ||
81 | }; | ||
63 | 82 | ||
64 | static ssize_t zorro_read_config(struct file *filp, struct kobject *kobj, | 83 | static ssize_t zorro_read_config(struct file *filp, struct kobject *kobj, |
65 | struct bin_attribute *bin_attr, | 84 | struct bin_attribute *bin_attr, |
@@ -88,32 +107,17 @@ static struct bin_attribute zorro_config_attr = { | |||
88 | .read = zorro_read_config, | 107 | .read = zorro_read_config, |
89 | }; | 108 | }; |
90 | 109 | ||
91 | static ssize_t modalias_show(struct device *dev, struct device_attribute *attr, | 110 | static struct bin_attribute *zorro_device_bin_attrs[] = { |
92 | char *buf) | 111 | &zorro_config_attr, |
93 | { | 112 | NULL |
94 | struct zorro_dev *z = to_zorro_dev(dev); | 113 | }; |
95 | |||
96 | return sprintf(buf, ZORRO_DEVICE_MODALIAS_FMT "\n", z->id); | ||
97 | } | ||
98 | |||
99 | static DEVICE_ATTR(modalias, S_IRUGO, modalias_show, NULL); | ||
100 | 114 | ||
101 | int zorro_create_sysfs_dev_files(struct zorro_dev *z) | 115 | static const struct attribute_group zorro_device_attr_group = { |
102 | { | 116 | .attrs = zorro_device_attrs, |
103 | struct device *dev = &z->dev; | 117 | .bin_attrs = zorro_device_bin_attrs, |
104 | int error; | 118 | }; |
105 | |||
106 | /* current configuration's attributes */ | ||
107 | if ((error = device_create_file(dev, &dev_attr_id)) || | ||
108 | (error = device_create_file(dev, &dev_attr_type)) || | ||
109 | (error = device_create_file(dev, &dev_attr_serial)) || | ||
110 | (error = device_create_file(dev, &dev_attr_slotaddr)) || | ||
111 | (error = device_create_file(dev, &dev_attr_slotsize)) || | ||
112 | (error = device_create_file(dev, &dev_attr_resource)) || | ||
113 | (error = device_create_file(dev, &dev_attr_modalias)) || | ||
114 | (error = sysfs_create_bin_file(&dev->kobj, &zorro_config_attr))) | ||
115 | return error; | ||
116 | |||
117 | return 0; | ||
118 | } | ||
119 | 119 | ||
120 | const struct attribute_group *zorro_device_attribute_groups[] = { | ||
121 | &zorro_device_attr_group, | ||
122 | NULL | ||
123 | }; | ||
diff --git a/drivers/zorro/zorro.c b/drivers/zorro/zorro.c index d295d9878dff..cc1b1ac57d61 100644 --- a/drivers/zorro/zorro.c +++ b/drivers/zorro/zorro.c | |||
@@ -197,9 +197,6 @@ static int __init amiga_zorro_probe(struct platform_device *pdev) | |||
197 | put_device(&z->dev); | 197 | put_device(&z->dev); |
198 | continue; | 198 | continue; |
199 | } | 199 | } |
200 | error = zorro_create_sysfs_dev_files(z); | ||
201 | if (error) | ||
202 | dev_err(&z->dev, "Error creating sysfs files\n"); | ||
203 | } | 200 | } |
204 | 201 | ||
205 | /* Mark all available Zorro II memory */ | 202 | /* Mark all available Zorro II memory */ |
diff --git a/drivers/zorro/zorro.h b/drivers/zorro/zorro.h index 34119fb4e560..4f805c01cfbc 100644 --- a/drivers/zorro/zorro.h +++ b/drivers/zorro/zorro.h | |||
@@ -5,5 +5,4 @@ extern void zorro_name_device(struct zorro_dev *z); | |||
5 | static inline void zorro_name_device(struct zorro_dev *dev) { } | 5 | static inline void zorro_name_device(struct zorro_dev *dev) { } |
6 | #endif | 6 | #endif |
7 | 7 | ||
8 | extern int zorro_create_sysfs_dev_files(struct zorro_dev *z); | 8 | extern const struct attribute_group *zorro_device_attribute_groups[]; |
9 | |||