1
0
Fork 0

hwmon: (ina209) Use permission specific SENSOR[_DEVICE]_ATTR variants

Use SENSOR[_DEVICE]_ATTR[_2]_{RO,RW,WO} to simplify the source code,
to improve readability, and to reduce the chance of inconsistencies.

Also replace any remaining S_<PERMS> in the driver with octal values.

The conversion was done automatically with coccinelle. The semantic patches
and the scripts used to generate this commit log are available at
https://github.com/groeck/coccinelle-patches/hwmon/.

This patch does not introduce functional changes. It was verified by
compiling the old and new files and comparing text and data sizes.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
hifive-unleashed-5.1
Guenter Roeck 2018-12-10 14:02:10 -08:00
parent 389bc38eeb
commit 46dce7a195
1 changed files with 62 additions and 83 deletions

View File

@ -230,9 +230,9 @@ static u16 ina209_reg_from_interval(u16 config, long interval)
return (config & 0xf807) | (adc << 3) | (adc << 7); return (config & 0xf807) | (adc << 3) | (adc << 7);
} }
static ssize_t ina209_set_interval(struct device *dev, static ssize_t ina209_interval_store(struct device *dev,
struct device_attribute *da, struct device_attribute *da,
const char *buf, size_t count) const char *buf, size_t count)
{ {
struct ina209_data *data = ina209_update_device(dev); struct ina209_data *data = ina209_update_device(dev);
long val; long val;
@ -257,7 +257,7 @@ static ssize_t ina209_set_interval(struct device *dev,
return count; return count;
} }
static ssize_t ina209_show_interval(struct device *dev, static ssize_t ina209_interval_show(struct device *dev,
struct device_attribute *da, char *buf) struct device_attribute *da, char *buf)
{ {
struct ina209_data *data = dev_get_drvdata(dev); struct ina209_data *data = dev_get_drvdata(dev);
@ -279,10 +279,9 @@ static u16 ina209_reset_history_regs[] = {
INA209_POWER_PEAK INA209_POWER_PEAK
}; };
static ssize_t ina209_reset_history(struct device *dev, static ssize_t ina209_history_store(struct device *dev,
struct device_attribute *da, struct device_attribute *da,
const char *buf, const char *buf, size_t count)
size_t count)
{ {
struct sensor_device_attribute *attr = to_sensor_dev_attr(da); struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
struct ina209_data *data = dev_get_drvdata(dev); struct ina209_data *data = dev_get_drvdata(dev);
@ -306,10 +305,9 @@ static ssize_t ina209_reset_history(struct device *dev,
return count; return count;
} }
static ssize_t ina209_set_value(struct device *dev, static ssize_t ina209_value_store(struct device *dev,
struct device_attribute *da, struct device_attribute *da,
const char *buf, const char *buf, size_t count)
size_t count)
{ {
struct ina209_data *data = ina209_update_device(dev); struct ina209_data *data = ina209_update_device(dev);
struct sensor_device_attribute *attr = to_sensor_dev_attr(da); struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
@ -337,9 +335,8 @@ abort:
return count; return count;
} }
static ssize_t ina209_show_value(struct device *dev, static ssize_t ina209_value_show(struct device *dev,
struct device_attribute *da, struct device_attribute *da, char *buf)
char *buf)
{ {
struct sensor_device_attribute *attr = to_sensor_dev_attr(da); struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
struct ina209_data *data = ina209_update_device(dev); struct ina209_data *data = ina209_update_device(dev);
@ -352,9 +349,8 @@ static ssize_t ina209_show_value(struct device *dev,
return snprintf(buf, PAGE_SIZE, "%ld\n", val); return snprintf(buf, PAGE_SIZE, "%ld\n", val);
} }
static ssize_t ina209_show_alarm(struct device *dev, static ssize_t ina209_alarm_show(struct device *dev,
struct device_attribute *da, struct device_attribute *da, char *buf)
char *buf)
{ {
struct sensor_device_attribute *attr = to_sensor_dev_attr(da); struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
struct ina209_data *data = ina209_update_device(dev); struct ina209_data *data = ina209_update_device(dev);
@ -374,82 +370,65 @@ static ssize_t ina209_show_alarm(struct device *dev,
} }
/* Shunt voltage, history, limits, alarms */ /* Shunt voltage, history, limits, alarms */
static SENSOR_DEVICE_ATTR(in0_input, S_IRUGO, ina209_show_value, NULL, static SENSOR_DEVICE_ATTR_RO(in0_input, ina209_value, INA209_SHUNT_VOLTAGE);
INA209_SHUNT_VOLTAGE); static SENSOR_DEVICE_ATTR_RO(in0_input_highest, ina209_value,
static SENSOR_DEVICE_ATTR(in0_input_highest, S_IRUGO, ina209_show_value, NULL, INA209_SHUNT_VOLTAGE_POS_PEAK);
INA209_SHUNT_VOLTAGE_POS_PEAK); static SENSOR_DEVICE_ATTR_RO(in0_input_lowest, ina209_value,
static SENSOR_DEVICE_ATTR(in0_input_lowest, S_IRUGO, ina209_show_value, NULL, INA209_SHUNT_VOLTAGE_NEG_PEAK);
INA209_SHUNT_VOLTAGE_NEG_PEAK); static SENSOR_DEVICE_ATTR_WO(in0_reset_history, ina209_history,
static SENSOR_DEVICE_ATTR(in0_reset_history, S_IWUSR, NULL, (1 << 0) | (1 << 1));
ina209_reset_history, (1 << 0) | (1 << 1)); static SENSOR_DEVICE_ATTR_RW(in0_max, ina209_value,
static SENSOR_DEVICE_ATTR(in0_max, S_IRUGO | S_IWUSR, ina209_show_value, INA209_SHUNT_VOLTAGE_POS_WARN);
ina209_set_value, INA209_SHUNT_VOLTAGE_POS_WARN); static SENSOR_DEVICE_ATTR_RW(in0_min, ina209_value,
static SENSOR_DEVICE_ATTR(in0_min, S_IRUGO | S_IWUSR, ina209_show_value, INA209_SHUNT_VOLTAGE_NEG_WARN);
ina209_set_value, INA209_SHUNT_VOLTAGE_NEG_WARN); static SENSOR_DEVICE_ATTR_RW(in0_crit_max, ina209_value,
static SENSOR_DEVICE_ATTR(in0_crit_max, S_IRUGO | S_IWUSR, ina209_show_value, INA209_CRITICAL_DAC_POS);
ina209_set_value, INA209_CRITICAL_DAC_POS); static SENSOR_DEVICE_ATTR_RW(in0_crit_min, ina209_value,
static SENSOR_DEVICE_ATTR(in0_crit_min, S_IRUGO | S_IWUSR, ina209_show_value, INA209_CRITICAL_DAC_NEG);
ina209_set_value, INA209_CRITICAL_DAC_NEG);
static SENSOR_DEVICE_ATTR(in0_min_alarm, S_IRUGO, ina209_show_alarm, NULL, static SENSOR_DEVICE_ATTR_RO(in0_min_alarm, ina209_alarm, 1 << 11);
1 << 11); static SENSOR_DEVICE_ATTR_RO(in0_max_alarm, ina209_alarm, 1 << 12);
static SENSOR_DEVICE_ATTR(in0_max_alarm, S_IRUGO, ina209_show_alarm, NULL, static SENSOR_DEVICE_ATTR_RO(in0_crit_min_alarm, ina209_alarm, 1 << 6);
1 << 12); static SENSOR_DEVICE_ATTR_RO(in0_crit_max_alarm, ina209_alarm, 1 << 7);
static SENSOR_DEVICE_ATTR(in0_crit_min_alarm, S_IRUGO, ina209_show_alarm, NULL,
1 << 6);
static SENSOR_DEVICE_ATTR(in0_crit_max_alarm, S_IRUGO, ina209_show_alarm, NULL,
1 << 7);
/* Bus voltage, history, limits, alarms */ /* Bus voltage, history, limits, alarms */
static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO, ina209_show_value, NULL, static SENSOR_DEVICE_ATTR_RO(in1_input, ina209_value, INA209_BUS_VOLTAGE);
INA209_BUS_VOLTAGE); static SENSOR_DEVICE_ATTR_RO(in1_input_highest, ina209_value,
static SENSOR_DEVICE_ATTR(in1_input_highest, S_IRUGO, ina209_show_value, NULL, INA209_BUS_VOLTAGE_MAX_PEAK);
INA209_BUS_VOLTAGE_MAX_PEAK); static SENSOR_DEVICE_ATTR_RO(in1_input_lowest, ina209_value,
static SENSOR_DEVICE_ATTR(in1_input_lowest, S_IRUGO, ina209_show_value, NULL, INA209_BUS_VOLTAGE_MIN_PEAK);
INA209_BUS_VOLTAGE_MIN_PEAK); static SENSOR_DEVICE_ATTR_WO(in1_reset_history, ina209_history,
static SENSOR_DEVICE_ATTR(in1_reset_history, S_IWUSR, NULL, (1 << 2) | (1 << 3));
ina209_reset_history, (1 << 2) | (1 << 3)); static SENSOR_DEVICE_ATTR_RW(in1_max, ina209_value,
static SENSOR_DEVICE_ATTR(in1_max, S_IRUGO | S_IWUSR, ina209_show_value, INA209_BUS_VOLTAGE_OVER_WARN);
ina209_set_value, INA209_BUS_VOLTAGE_OVER_WARN); static SENSOR_DEVICE_ATTR_RW(in1_min, ina209_value,
static SENSOR_DEVICE_ATTR(in1_min, S_IRUGO | S_IWUSR, ina209_show_value, INA209_BUS_VOLTAGE_UNDER_WARN);
ina209_set_value, INA209_BUS_VOLTAGE_UNDER_WARN); static SENSOR_DEVICE_ATTR_RW(in1_crit_max, ina209_value,
static SENSOR_DEVICE_ATTR(in1_crit_max, S_IRUGO | S_IWUSR, ina209_show_value, INA209_BUS_VOLTAGE_OVER_LIMIT);
ina209_set_value, INA209_BUS_VOLTAGE_OVER_LIMIT); static SENSOR_DEVICE_ATTR_RW(in1_crit_min, ina209_value,
static SENSOR_DEVICE_ATTR(in1_crit_min, S_IRUGO | S_IWUSR, ina209_show_value, INA209_BUS_VOLTAGE_UNDER_LIMIT);
ina209_set_value, INA209_BUS_VOLTAGE_UNDER_LIMIT);
static SENSOR_DEVICE_ATTR(in1_min_alarm, S_IRUGO, ina209_show_alarm, NULL, static SENSOR_DEVICE_ATTR_RO(in1_min_alarm, ina209_alarm, 1 << 14);
1 << 14); static SENSOR_DEVICE_ATTR_RO(in1_max_alarm, ina209_alarm, 1 << 15);
static SENSOR_DEVICE_ATTR(in1_max_alarm, S_IRUGO, ina209_show_alarm, NULL, static SENSOR_DEVICE_ATTR_RO(in1_crit_min_alarm, ina209_alarm, 1 << 9);
1 << 15); static SENSOR_DEVICE_ATTR_RO(in1_crit_max_alarm, ina209_alarm, 1 << 10);
static SENSOR_DEVICE_ATTR(in1_crit_min_alarm, S_IRUGO, ina209_show_alarm, NULL,
1 << 9);
static SENSOR_DEVICE_ATTR(in1_crit_max_alarm, S_IRUGO, ina209_show_alarm, NULL,
1 << 10);
/* Power */ /* Power */
static SENSOR_DEVICE_ATTR(power1_input, S_IRUGO, ina209_show_value, NULL, static SENSOR_DEVICE_ATTR_RO(power1_input, ina209_value, INA209_POWER);
INA209_POWER); static SENSOR_DEVICE_ATTR_RO(power1_input_highest, ina209_value,
static SENSOR_DEVICE_ATTR(power1_input_highest, S_IRUGO, ina209_show_value, INA209_POWER_PEAK);
NULL, INA209_POWER_PEAK); static SENSOR_DEVICE_ATTR_WO(power1_reset_history, ina209_history, 1 << 4);
static SENSOR_DEVICE_ATTR(power1_reset_history, S_IWUSR, NULL, static SENSOR_DEVICE_ATTR_RW(power1_max, ina209_value, INA209_POWER_WARN);
ina209_reset_history, 1 << 4); static SENSOR_DEVICE_ATTR_RW(power1_crit, ina209_value,
static SENSOR_DEVICE_ATTR(power1_max, S_IRUGO | S_IWUSR, ina209_show_value, INA209_POWER_OVER_LIMIT);
ina209_set_value, INA209_POWER_WARN);
static SENSOR_DEVICE_ATTR(power1_crit, S_IRUGO | S_IWUSR, ina209_show_value,
ina209_set_value, INA209_POWER_OVER_LIMIT);
static SENSOR_DEVICE_ATTR(power1_max_alarm, S_IRUGO, ina209_show_alarm, NULL, static SENSOR_DEVICE_ATTR_RO(power1_max_alarm, ina209_alarm, 1 << 13);
1 << 13); static SENSOR_DEVICE_ATTR_RO(power1_crit_alarm, ina209_alarm, 1 << 8);
static SENSOR_DEVICE_ATTR(power1_crit_alarm, S_IRUGO, ina209_show_alarm, NULL,
1 << 8);
/* Current */ /* Current */
static SENSOR_DEVICE_ATTR(curr1_input, S_IRUGO, ina209_show_value, NULL, static SENSOR_DEVICE_ATTR_RO(curr1_input, ina209_value, INA209_CURRENT);
INA209_CURRENT);
static SENSOR_DEVICE_ATTR(update_interval, S_IRUGO | S_IWUSR, static SENSOR_DEVICE_ATTR_RW(update_interval, ina209_interval, 0);
ina209_show_interval, ina209_set_interval, 0);
/* /*
* Finally, construct an array of pointers to members of the above objects, * Finally, construct an array of pointers to members of the above objects,