Commit 973018b1 authored by Guenter Roeck's avatar Guenter Roeck

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: default avatarGuenter Roeck <linux@roeck-us.net>
parent 77493ef6
...@@ -809,42 +809,43 @@ static ssize_t pmbus_show_label(struct device *dev, ...@@ -809,42 +809,43 @@ static ssize_t pmbus_show_label(struct device *dev,
data->labels[attr->index].label); data->labels[attr->index].label);
} }
#define PMBUS_ADD_ATTR(data, _name, _idx, _mode, _type, _show, _set) \ static void pmbus_attr_init(struct sensor_device_attribute *a,
do { \ const char *name,
struct sensor_device_attribute *a \ umode_t mode,
= &data->_type##s[data->num_##_type##s].attribute; \ ssize_t (*show)(struct device *dev,
BUG_ON(data->num_attributes >= data->max_attributes); \ struct device_attribute *attr,
sysfs_attr_init(&a->dev_attr.attr); \ char *buf),
a->dev_attr.attr.name = _name; \ ssize_t (*store)(struct device *dev,
a->dev_attr.attr.mode = _mode; \ struct device_attribute *attr,
a->dev_attr.show = _show; \ const char *buf, size_t count),
a->dev_attr.store = _set; \ int idx)
a->index = _idx; \ {
data->attributes[data->num_attributes] = &a->dev_attr.attr; \ sysfs_attr_init(&a->dev_attr.attr);
data->num_attributes++; \ a->dev_attr.attr.name = name;
} while (0) a->dev_attr.attr.mode = mode;
a->dev_attr.show = show;
#define PMBUS_ADD_GET_ATTR(data, _name, _type, _idx) \ a->dev_attr.store = store;
PMBUS_ADD_ATTR(data, _name, _idx, S_IRUGO, _type, \ a->index = idx;
pmbus_show_##_type, NULL) }
#define PMBUS_ADD_SET_ATTR(data, _name, _type, _idx) \
PMBUS_ADD_ATTR(data, _name, _idx, S_IWUSR | S_IRUGO, _type, \
pmbus_show_##_type, pmbus_set_##_type)
static void pmbus_add_boolean(struct pmbus_data *data, static void pmbus_add_boolean(struct pmbus_data *data,
const char *name, const char *type, int seq, const char *name, const char *type, int seq,
int idx) int idx)
{ {
struct pmbus_boolean *boolean; struct pmbus_boolean *boolean;
struct sensor_device_attribute *a;
BUG_ON(data->num_booleans >= data->max_booleans); BUG_ON(data->num_booleans >= data->max_booleans ||
data->num_attributes >= data->max_attributes);
boolean = &data->booleans[data->num_booleans]; boolean = &data->booleans[data->num_booleans];
a = &boolean->attribute;
snprintf(boolean->name, sizeof(boolean->name), "%s%d_%s", snprintf(boolean->name, sizeof(boolean->name), "%s%d_%s",
name, seq, type); name, seq, type);
PMBUS_ADD_GET_ATTR(data, boolean->name, boolean, idx); pmbus_attr_init(a, boolean->name, S_IRUGO, pmbus_show_boolean, NULL,
idx);
data->attributes[data->num_attributes++] = &a->dev_attr.attr;
data->num_booleans++; data->num_booleans++;
} }
...@@ -869,22 +870,25 @@ static void pmbus_add_sensor(struct pmbus_data *data, ...@@ -869,22 +870,25 @@ static void pmbus_add_sensor(struct pmbus_data *data,
bool update, bool readonly) bool update, bool readonly)
{ {
struct pmbus_sensor *sensor; struct pmbus_sensor *sensor;
struct sensor_device_attribute *a;
BUG_ON(data->num_sensors >= data->max_sensors); BUG_ON(data->num_sensors >= data->max_sensors ||
data->num_attributes >= data->max_attributes);
sensor = &data->sensors[data->num_sensors]; sensor = &data->sensors[data->num_sensors];
a = &sensor->attribute;
snprintf(sensor->name, sizeof(sensor->name), "%s%d_%s", snprintf(sensor->name, sizeof(sensor->name), "%s%d_%s",
name, seq, type); name, seq, type);
sensor->page = page; sensor->page = page;
sensor->reg = reg; sensor->reg = reg;
sensor->class = class; sensor->class = class;
sensor->update = update; sensor->update = update;
if (readonly) pmbus_attr_init(a, sensor->name,
PMBUS_ADD_GET_ATTR(data, sensor->name, sensor, readonly ? S_IRUGO : S_IRUGO | S_IWUSR,
data->num_sensors); pmbus_show_sensor, pmbus_set_sensor, data->num_sensors);
else
PMBUS_ADD_SET_ATTR(data, sensor->name, sensor, data->attributes[data->num_attributes++] = &a->dev_attr.attr;
data->num_sensors);
data->num_sensors++; data->num_sensors++;
} }
...@@ -893,10 +897,14 @@ static void pmbus_add_label(struct pmbus_data *data, ...@@ -893,10 +897,14 @@ static void pmbus_add_label(struct pmbus_data *data,
const char *lstring, int index) const char *lstring, int index)
{ {
struct pmbus_label *label; struct pmbus_label *label;
struct sensor_device_attribute *a;
BUG_ON(data->num_labels >= data->max_labels); BUG_ON(data->num_labels >= data->max_labels ||
data->num_attributes >= data->max_attributes);
label = &data->labels[data->num_labels]; label = &data->labels[data->num_labels];
a = &label->attribute;
snprintf(label->name, sizeof(label->name), "%s%d_label", name, seq); snprintf(label->name, sizeof(label->name), "%s%d_label", name, seq);
if (!index) if (!index)
strncpy(label->label, lstring, sizeof(label->label) - 1); strncpy(label->label, lstring, sizeof(label->label) - 1);
...@@ -904,7 +912,9 @@ static void pmbus_add_label(struct pmbus_data *data, ...@@ -904,7 +912,9 @@ static void pmbus_add_label(struct pmbus_data *data,
snprintf(label->label, sizeof(label->label), "%s%d", lstring, snprintf(label->label, sizeof(label->label), "%s%d", lstring,
index); index);
PMBUS_ADD_GET_ATTR(data, label->name, label, data->num_labels); pmbus_attr_init(a, label->name, S_IRUGO, pmbus_show_label, NULL,
data->num_labels);
data->attributes[data->num_attributes++] = &a->dev_attr.attr;
data->num_labels++; data->num_labels++;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment