Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Dmitry Torokhov and committed by
Greg Kroah-Hartman
87e715de a553910f

+50 -47
+9 -6
drivers/zorro/zorro-driver.c
··· 14 14 #include <linux/module.h> 15 15 #include <linux/zorro.h> 16 16 17 + #include "zorro.h" 18 + 17 19 18 20 /** 19 21 * zorro_match_device - Tell if a Zorro device structure has a matching ··· 163 161 } 164 162 165 163 struct bus_type zorro_bus_type = { 166 - .name = "zorro", 167 - .dev_name = "zorro", 168 - .match = zorro_bus_match, 169 - .uevent = zorro_uevent, 170 - .probe = zorro_device_probe, 171 - .remove = zorro_device_remove, 164 + .name = "zorro", 165 + .dev_name = "zorro", 166 + .dev_groups = zorro_device_attribute_groups, 167 + .match = zorro_bus_match, 168 + .uevent = zorro_uevent, 169 + .probe = zorro_device_probe, 170 + .remove = zorro_device_remove, 172 171 }; 173 172 EXPORT_SYMBOL(zorro_bus_type); 174 173
+40 -36
drivers/zorro/zorro-sysfs.c
··· 23 23 24 24 /* show configuration fields */ 25 25 #define zorro_config_attr(name, field, format_string) \ 26 - static ssize_t \ 27 - show_##name(struct device *dev, struct device_attribute *attr, char *buf) \ 26 + static ssize_t name##_show(struct device *dev, \ 27 + struct device_attribute *attr, char *buf) \ 28 28 { \ 29 29 struct zorro_dev *z; \ 30 30 \ 31 31 z = to_zorro_dev(dev); \ 32 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 36 zorro_config_attr(id, id, "0x%08x\n"); 37 37 zorro_config_attr(type, rom.er_Type, "0x%02x\n"); 38 38 zorro_config_attr(slotaddr, slotaddr, "0x%04x\n"); 39 39 zorro_config_attr(slotsize, slotsize, "0x%04x\n"); 40 40 41 - static ssize_t 42 - show_serial(struct device *dev, struct device_attribute *attr, char *buf) 41 + static ssize_t serial_show(struct device *dev, struct device_attribute *attr, 42 + char *buf) 43 43 { 44 44 struct zorro_dev *z; 45 45 46 46 z = to_zorro_dev(dev); 47 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 - 52 - static ssize_t zorro_show_resource(struct device *dev, struct device_attribute *attr, char *buf) 51 + static ssize_t resource_show(struct device *dev, struct device_attribute *attr, 52 + char *buf) 53 53 { 54 54 struct zorro_dev *z = to_zorro_dev(dev); 55 55 ··· 58 58 (unsigned long)zorro_resource_end(z), 59 59 zorro_resource_flags(z)); 60 60 } 61 + static DEVICE_ATTR_RO(resource); 61 62 62 - static DEVICE_ATTR(resource, S_IRUGO, zorro_show_resource, NULL); 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); 67 + 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 83 static ssize_t zorro_read_config(struct file *filp, struct kobject *kobj, 65 84 struct bin_attribute *bin_attr, ··· 107 88 .read = zorro_read_config, 108 89 }; 109 90 110 - static ssize_t modalias_show(struct device *dev, struct device_attribute *attr, 111 - char *buf) 112 - { 113 - struct zorro_dev *z = to_zorro_dev(dev); 91 + static struct bin_attribute *zorro_device_bin_attrs[] = { 92 + &zorro_config_attr, 93 + NULL 94 + }; 114 95 115 - return sprintf(buf, ZORRO_DEVICE_MODALIAS_FMT "\n", z->id); 116 - } 96 + static const struct attribute_group zorro_device_attr_group = { 97 + .attrs = zorro_device_attrs, 98 + .bin_attrs = zorro_device_bin_attrs, 99 + }; 117 100 118 - static DEVICE_ATTR(modalias, S_IRUGO, modalias_show, NULL); 119 - 120 - int zorro_create_sysfs_dev_files(struct zorro_dev *z) 121 - { 122 - struct device *dev = &z->dev; 123 - int error; 124 - 125 - /* current configuration's attributes */ 126 - if ((error = device_create_file(dev, &dev_attr_id)) || 127 - (error = device_create_file(dev, &dev_attr_type)) || 128 - (error = device_create_file(dev, &dev_attr_serial)) || 129 - (error = device_create_file(dev, &dev_attr_slotaddr)) || 130 - (error = device_create_file(dev, &dev_attr_slotsize)) || 131 - (error = device_create_file(dev, &dev_attr_resource)) || 132 - (error = device_create_file(dev, &dev_attr_modalias)) || 133 - (error = sysfs_create_bin_file(&dev->kobj, &zorro_config_attr))) 134 - return error; 135 - 136 - return 0; 137 - } 138 - 101 + const struct attribute_group *zorro_device_attribute_groups[] = { 102 + &zorro_device_attr_group, 103 + NULL 104 + };
-3
drivers/zorro/zorro.c
··· 197 197 put_device(&z->dev); 198 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 202 /* Mark all available Zorro II memory */
+1 -2
drivers/zorro/zorro.h
··· 5 5 static inline void zorro_name_device(struct zorro_dev *dev) { } 6 6 #endif 7 7 8 - extern int zorro_create_sysfs_dev_files(struct zorro_dev *z); 9 - 8 + extern const struct attribute_group *zorro_device_attribute_groups[];