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

i2c: simplify boilerplate code for attribute groups

Declaring attribute groups can be done with macros these days, let's use
them for consistency and readability reasons. Also, put the ATTR macros
directly below the referenced functions while we are here.

Signed-off-by: Wolfram Sang <wsa@the-dreams.de>

+6 -24
+6 -24
drivers/i2c/i2c-core.c
··· 709 709 return sprintf(buf, "%s\n", dev->type == &i2c_client_type ? 710 710 to_i2c_client(dev)->name : to_i2c_adapter(dev)->name); 711 711 } 712 + static DEVICE_ATTR(name, S_IRUGO, show_name, NULL); 712 713 713 714 static ssize_t 714 715 show_modalias(struct device *dev, struct device_attribute *attr, char *buf) ··· 723 722 724 723 return sprintf(buf, "%s%s\n", I2C_MODULE_PREFIX, client->name); 725 724 } 726 - 727 - static DEVICE_ATTR(name, S_IRUGO, show_name, NULL); 728 725 static DEVICE_ATTR(modalias, S_IRUGO, show_modalias, NULL); 729 726 730 727 static struct attribute *i2c_dev_attrs[] = { ··· 731 732 &dev_attr_modalias.attr, 732 733 NULL 733 734 }; 734 - 735 - static struct attribute_group i2c_dev_attr_group = { 736 - .attrs = i2c_dev_attrs, 737 - }; 738 - 739 - static const struct attribute_group *i2c_dev_attr_groups[] = { 740 - &i2c_dev_attr_group, 741 - NULL 742 - }; 735 + ATTRIBUTE_GROUPS(i2c_dev); 743 736 744 737 struct bus_type i2c_bus_type = { 745 738 .name = "i2c", ··· 743 752 EXPORT_SYMBOL_GPL(i2c_bus_type); 744 753 745 754 static struct device_type i2c_client_type = { 746 - .groups = i2c_dev_attr_groups, 755 + .groups = i2c_dev_groups, 747 756 .uevent = i2c_device_uevent, 748 757 .release = i2c_client_dev_release, 749 758 }; ··· 1142 1151 1143 1152 return count; 1144 1153 } 1154 + static DEVICE_ATTR(new_device, S_IWUSR, NULL, i2c_sysfs_new_device); 1145 1155 1146 1156 /* 1147 1157 * And of course let the users delete the devices they instantiated, if ··· 1197 1205 "delete_device"); 1198 1206 return res; 1199 1207 } 1200 - 1201 - static DEVICE_ATTR(new_device, S_IWUSR, NULL, i2c_sysfs_new_device); 1202 1208 static DEVICE_ATTR_IGNORE_LOCKDEP(delete_device, S_IWUSR, NULL, 1203 1209 i2c_sysfs_delete_device); 1204 1210 ··· 1206 1216 &dev_attr_delete_device.attr, 1207 1217 NULL 1208 1218 }; 1209 - 1210 - static struct attribute_group i2c_adapter_attr_group = { 1211 - .attrs = i2c_adapter_attrs, 1212 - }; 1213 - 1214 - static const struct attribute_group *i2c_adapter_attr_groups[] = { 1215 - &i2c_adapter_attr_group, 1216 - NULL 1217 - }; 1219 + ATTRIBUTE_GROUPS(i2c_adapter); 1218 1220 1219 1221 struct device_type i2c_adapter_type = { 1220 - .groups = i2c_adapter_attr_groups, 1222 + .groups = i2c_adapter_groups, 1221 1223 .release = i2c_adapter_dev_release, 1222 1224 }; 1223 1225 EXPORT_SYMBOL_GPL(i2c_adapter_type);