diff options
author | Guenter Roeck <linux@roeck-us.net> | 2013-01-19 23:59:04 -0500 |
---|---|---|
committer | Guenter Roeck <linux@roeck-us.net> | 2013-02-06 12:58:00 -0500 |
commit | 973018b1b75abd696304207f016875d1fce2dbf4 (patch) | |
tree | df29931e4c40b408868f125410b6af143e9b8463 /drivers/hwmon/pmbus | |
parent | 77493ef60f4586a58f83a3a00a55eeb733b4eff3 (diff) |
hwmon: (pmbus) Fix 'Macros with multiple statements' checkpatch error
Fix:
ERROR: Macros with multiple statements should be enclosed in a do - while loop
by unwinding the problematic macros.
As a side effect, this patch reduces code size on x86_64 by 160 bytes and bss
size by 64 bytes.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Diffstat (limited to 'drivers/hwmon/pmbus')
-rw-r--r-- | drivers/hwmon/pmbus/pmbus_core.c | 76 |
1 files changed, 43 insertions, 33 deletions
diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c index e3eb3249d912..b9ba8ce1f3f1 100644 --- a/drivers/hwmon/pmbus/pmbus_core.c +++ b/drivers/hwmon/pmbus/pmbus_core.c | |||
@@ -809,42 +809,43 @@ static ssize_t pmbus_show_label(struct device *dev, | |||
809 | data->labels[attr->index].label); | 809 | data->labels[attr->index].label); |
810 | } | 810 | } |
811 | 811 | ||
812 | #define PMBUS_ADD_ATTR(data, _name, _idx, _mode, _type, _show, _set) \ | 812 | static void pmbus_attr_init(struct sensor_device_attribute *a, |
813 | do { \ | 813 | const char *name, |
814 | struct sensor_device_attribute *a \ | 814 | umode_t mode, |
815 | = &data->_type##s[data->num_##_type##s].attribute; \ | 815 | ssize_t (*show)(struct device *dev, |
816 | BUG_ON(data->num_attributes >= data->max_attributes); \ | 816 | struct device_attribute *attr, |
817 | sysfs_attr_init(&a->dev_attr.attr); \ | 817 | char *buf), |
818 | a->dev_attr.attr.name = _name; \ | 818 | ssize_t (*store)(struct device *dev, |
819 | a->dev_attr.attr.mode = _mode; \ | 819 | struct device_attribute *attr, |
820 | a->dev_attr.show = _show; \ | 820 | const char *buf, size_t count), |
821 | a->dev_attr.store = _set; \ | 821 | int idx) |
822 | a->index = _idx; \ | 822 | { |
823 | data->attributes[data->num_attributes] = &a->dev_attr.attr; \ | 823 | sysfs_attr_init(&a->dev_attr.attr); |
824 | data->num_attributes++; \ | 824 | a->dev_attr.attr.name = name; |
825 | } while (0) | 825 | a->dev_attr.attr.mode = mode; |
826 | 826 | a->dev_attr.show = show; | |
827 | #define PMBUS_ADD_GET_ATTR(data, _name, _type, _idx) \ | 827 | a->dev_attr.store = store; |
828 | PMBUS_ADD_ATTR(data, _name, _idx, S_IRUGO, _type, \ | 828 | a->index = idx; |
829 | pmbus_show_##_type, NULL) | 829 | } |
830 | |||
831 | #define PMBUS_ADD_SET_ATTR(data, _name, _type, _idx) \ | ||
832 | PMBUS_ADD_ATTR(data, _name, _idx, S_IWUSR | S_IRUGO, _type, \ | ||
833 | pmbus_show_##_type, pmbus_set_##_type) | ||
834 | 830 | ||
835 | static void pmbus_add_boolean(struct pmbus_data *data, | 831 | static void pmbus_add_boolean(struct pmbus_data *data, |
836 | const char *name, const char *type, int seq, | 832 | const char *name, const char *type, int seq, |
837 | int idx) | 833 | int idx) |
838 | { | 834 | { |
839 | struct pmbus_boolean *boolean; | 835 | struct pmbus_boolean *boolean; |
836 | struct sensor_device_attribute *a; | ||
840 | 837 | ||
841 | BUG_ON(data->num_booleans >= data->max_booleans); | 838 | BUG_ON(data->num_booleans >= data->max_booleans || |
839 | data->num_attributes >= data->max_attributes); | ||
842 | 840 | ||
843 | boolean = &data->booleans[data->num_booleans]; | 841 | boolean = &data->booleans[data->num_booleans]; |
842 | a = &boolean->attribute; | ||
844 | 843 | ||
845 | snprintf(boolean->name, sizeof(boolean->name), "%s%d_%s", | 844 | snprintf(boolean->name, sizeof(boolean->name), "%s%d_%s", |
846 | name, seq, type); | 845 | name, seq, type); |
847 | PMBUS_ADD_GET_ATTR(data, boolean->name, boolean, idx); | 846 | pmbus_attr_init(a, boolean->name, S_IRUGO, pmbus_show_boolean, NULL, |
847 | idx); | ||
848 | data->attributes[data->num_attributes++] = &a->dev_attr.attr; | ||
848 | data->num_booleans++; | 849 | data->num_booleans++; |
849 | } | 850 | } |
850 | 851 | ||
@@ -869,22 +870,25 @@ static void pmbus_add_sensor(struct pmbus_data *data, | |||
869 | bool update, bool readonly) | 870 | bool update, bool readonly) |
870 | { | 871 | { |
871 | struct pmbus_sensor *sensor; | 872 | struct pmbus_sensor *sensor; |
873 | struct sensor_device_attribute *a; | ||
872 | 874 | ||
873 | BUG_ON(data->num_sensors >= data->max_sensors); | 875 | BUG_ON(data->num_sensors >= data->max_sensors || |
876 | data->num_attributes >= data->max_attributes); | ||
874 | 877 | ||
875 | sensor = &data->sensors[data->num_sensors]; | 878 | sensor = &data->sensors[data->num_sensors]; |
879 | a = &sensor->attribute; | ||
880 | |||
876 | snprintf(sensor->name, sizeof(sensor->name), "%s%d_%s", | 881 | snprintf(sensor->name, sizeof(sensor->name), "%s%d_%s", |
877 | name, seq, type); | 882 | name, seq, type); |
878 | sensor->page = page; | 883 | sensor->page = page; |
879 | sensor->reg = reg; | 884 | sensor->reg = reg; |
880 | sensor->class = class; | 885 | sensor->class = class; |
881 | sensor->update = update; | 886 | sensor->update = update; |
882 | if (readonly) | 887 | pmbus_attr_init(a, sensor->name, |
883 | PMBUS_ADD_GET_ATTR(data, sensor->name, sensor, | 888 | readonly ? S_IRUGO : S_IRUGO | S_IWUSR, |
884 | data->num_sensors); | 889 | pmbus_show_sensor, pmbus_set_sensor, data->num_sensors); |
885 | else | 890 | |
886 | PMBUS_ADD_SET_ATTR(data, sensor->name, sensor, | 891 | data->attributes[data->num_attributes++] = &a->dev_attr.attr; |
887 | data->num_sensors); | ||
888 | data->num_sensors++; | 892 | data->num_sensors++; |
889 | } | 893 | } |
890 | 894 | ||
@@ -893,10 +897,14 @@ static void pmbus_add_label(struct pmbus_data *data, | |||
893 | const char *lstring, int index) | 897 | const char *lstring, int index) |
894 | { | 898 | { |
895 | struct pmbus_label *label; | 899 | struct pmbus_label *label; |
900 | struct sensor_device_attribute *a; | ||
896 | 901 | ||
897 | BUG_ON(data->num_labels >= data->max_labels); | 902 | BUG_ON(data->num_labels >= data->max_labels || |
903 | data->num_attributes >= data->max_attributes); | ||
898 | 904 | ||
899 | label = &data->labels[data->num_labels]; | 905 | label = &data->labels[data->num_labels]; |
906 | a = &label->attribute; | ||
907 | |||
900 | snprintf(label->name, sizeof(label->name), "%s%d_label", name, seq); | 908 | snprintf(label->name, sizeof(label->name), "%s%d_label", name, seq); |
901 | if (!index) | 909 | if (!index) |
902 | strncpy(label->label, lstring, sizeof(label->label) - 1); | 910 | strncpy(label->label, lstring, sizeof(label->label) - 1); |
@@ -904,7 +912,9 @@ static void pmbus_add_label(struct pmbus_data *data, | |||
904 | snprintf(label->label, sizeof(label->label), "%s%d", lstring, | 912 | snprintf(label->label, sizeof(label->label), "%s%d", lstring, |
905 | index); | 913 | index); |
906 | 914 | ||
907 | PMBUS_ADD_GET_ATTR(data, label->name, label, data->num_labels); | 915 | pmbus_attr_init(a, label->name, S_IRUGO, pmbus_show_label, NULL, |
916 | data->num_labels); | ||
917 | data->attributes[data->num_attributes++] = &a->dev_attr.attr; | ||
908 | data->num_labels++; | 918 | data->num_labels++; |
909 | } | 919 | } |
910 | 920 | ||