Commit d5034db6 authored by Julia Lawall's avatar Julia Lawall Committed by Guenter Roeck

hwmon: (vt8231) use permission-specific DEVICE_ATTR variants

Use DEVICE_ATTR_RO for read only attributes and DEVICE_ATTR_RW for
read/write attributes. This simplifies the source code, improves
readbility, and reduces the chance of inconsistencies.

The conversion was done automatically using coccinelle. It was validated
by compiling both the old and the new source code and comparing its text,
data, and bss size.
Signed-off-by: default avatarJulia Lawall <Julia.Lawall@lip6.fr>
[groeck: Updated description]
Signed-off-by: default avatarGuenter Roeck <linux@roeck-us.net>
parent 329beb71
...@@ -263,8 +263,8 @@ static ssize_t set_in_max(struct device *dev, struct device_attribute *attr, ...@@ -263,8 +263,8 @@ static ssize_t set_in_max(struct device *dev, struct device_attribute *attr,
} }
/* Special case for input 5 as this has 3.3V scaling built into the chip */ /* Special case for input 5 as this has 3.3V scaling built into the chip */
static ssize_t show_in5(struct device *dev, struct device_attribute *attr, static ssize_t in5_input_show(struct device *dev,
char *buf) struct device_attribute *attr, char *buf)
{ {
struct vt8231_data *data = vt8231_update_device(dev); struct vt8231_data *data = vt8231_update_device(dev);
...@@ -272,7 +272,7 @@ static ssize_t show_in5(struct device *dev, struct device_attribute *attr, ...@@ -272,7 +272,7 @@ static ssize_t show_in5(struct device *dev, struct device_attribute *attr,
(((data->in[5] - 3) * 10000 * 54) / (958 * 34))); (((data->in[5] - 3) * 10000 * 54) / (958 * 34)));
} }
static ssize_t show_in5_min(struct device *dev, struct device_attribute *attr, static ssize_t in5_min_show(struct device *dev, struct device_attribute *attr,
char *buf) char *buf)
{ {
struct vt8231_data *data = vt8231_update_device(dev); struct vt8231_data *data = vt8231_update_device(dev);
...@@ -281,7 +281,7 @@ static ssize_t show_in5_min(struct device *dev, struct device_attribute *attr, ...@@ -281,7 +281,7 @@ static ssize_t show_in5_min(struct device *dev, struct device_attribute *attr,
(((data->in_min[5] - 3) * 10000 * 54) / (958 * 34))); (((data->in_min[5] - 3) * 10000 * 54) / (958 * 34)));
} }
static ssize_t show_in5_max(struct device *dev, struct device_attribute *attr, static ssize_t in5_max_show(struct device *dev, struct device_attribute *attr,
char *buf) char *buf)
{ {
struct vt8231_data *data = vt8231_update_device(dev); struct vt8231_data *data = vt8231_update_device(dev);
...@@ -290,8 +290,9 @@ static ssize_t show_in5_max(struct device *dev, struct device_attribute *attr, ...@@ -290,8 +290,9 @@ static ssize_t show_in5_max(struct device *dev, struct device_attribute *attr,
(((data->in_max[5] - 3) * 10000 * 54) / (958 * 34))); (((data->in_max[5] - 3) * 10000 * 54) / (958 * 34)));
} }
static ssize_t set_in5_min(struct device *dev, struct device_attribute *attr, static ssize_t in5_min_store(struct device *dev,
const char *buf, size_t count) struct device_attribute *attr, const char *buf,
size_t count)
{ {
struct vt8231_data *data = dev_get_drvdata(dev); struct vt8231_data *data = dev_get_drvdata(dev);
unsigned long val; unsigned long val;
...@@ -309,8 +310,9 @@ static ssize_t set_in5_min(struct device *dev, struct device_attribute *attr, ...@@ -309,8 +310,9 @@ static ssize_t set_in5_min(struct device *dev, struct device_attribute *attr,
return count; return count;
} }
static ssize_t set_in5_max(struct device *dev, struct device_attribute *attr, static ssize_t in5_max_store(struct device *dev,
const char *buf, size_t count) struct device_attribute *attr, const char *buf,
size_t count)
{ {
struct vt8231_data *data = dev_get_drvdata(dev); struct vt8231_data *data = dev_get_drvdata(dev);
unsigned long val; unsigned long val;
...@@ -342,34 +344,35 @@ define_voltage_sysfs(2); ...@@ -342,34 +344,35 @@ define_voltage_sysfs(2);
define_voltage_sysfs(3); define_voltage_sysfs(3);
define_voltage_sysfs(4); define_voltage_sysfs(4);
static DEVICE_ATTR(in5_input, S_IRUGO, show_in5, NULL); static DEVICE_ATTR_RO(in5_input);
static DEVICE_ATTR(in5_min, S_IRUGO | S_IWUSR, show_in5_min, set_in5_min); static DEVICE_ATTR_RW(in5_min);
static DEVICE_ATTR(in5_max, S_IRUGO | S_IWUSR, show_in5_max, set_in5_max); static DEVICE_ATTR_RW(in5_max);
/* Temperatures */ /* Temperatures */
static ssize_t show_temp0(struct device *dev, struct device_attribute *attr, static ssize_t temp1_input_show(struct device *dev,
char *buf) struct device_attribute *attr, char *buf)
{ {
struct vt8231_data *data = vt8231_update_device(dev); struct vt8231_data *data = vt8231_update_device(dev);
return sprintf(buf, "%d\n", data->temp[0] * 250); return sprintf(buf, "%d\n", data->temp[0] * 250);
} }
static ssize_t show_temp0_max(struct device *dev, struct device_attribute *attr, static ssize_t temp1_max_show(struct device *dev, struct device_attribute *attr,
char *buf) char *buf)
{ {
struct vt8231_data *data = vt8231_update_device(dev); struct vt8231_data *data = vt8231_update_device(dev);
return sprintf(buf, "%d\n", data->temp_max[0] * 1000); return sprintf(buf, "%d\n", data->temp_max[0] * 1000);
} }
static ssize_t show_temp0_min(struct device *dev, struct device_attribute *attr, static ssize_t temp1_max_hyst_show(struct device *dev,
char *buf) struct device_attribute *attr, char *buf)
{ {
struct vt8231_data *data = vt8231_update_device(dev); struct vt8231_data *data = vt8231_update_device(dev);
return sprintf(buf, "%d\n", data->temp_min[0] * 1000); return sprintf(buf, "%d\n", data->temp_min[0] * 1000);
} }
static ssize_t set_temp0_max(struct device *dev, struct device_attribute *attr, static ssize_t temp1_max_store(struct device *dev,
const char *buf, size_t count) struct device_attribute *attr, const char *buf,
size_t count)
{ {
struct vt8231_data *data = dev_get_drvdata(dev); struct vt8231_data *data = dev_get_drvdata(dev);
long val; long val;
...@@ -385,8 +388,9 @@ static ssize_t set_temp0_max(struct device *dev, struct device_attribute *attr, ...@@ -385,8 +388,9 @@ static ssize_t set_temp0_max(struct device *dev, struct device_attribute *attr,
mutex_unlock(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
static ssize_t set_temp0_min(struct device *dev, struct device_attribute *attr, static ssize_t temp1_max_hyst_store(struct device *dev,
const char *buf, size_t count) struct device_attribute *attr,
const char *buf, size_t count)
{ {
struct vt8231_data *data = dev_get_drvdata(dev); struct vt8231_data *data = dev_get_drvdata(dev);
long val; long val;
...@@ -481,10 +485,9 @@ static SENSOR_DEVICE_ATTR(temp##offset##_max, S_IRUGO | S_IWUSR, \ ...@@ -481,10 +485,9 @@ static SENSOR_DEVICE_ATTR(temp##offset##_max, S_IRUGO | S_IWUSR, \
static SENSOR_DEVICE_ATTR(temp##offset##_max_hyst, S_IRUGO | S_IWUSR, \ static SENSOR_DEVICE_ATTR(temp##offset##_max_hyst, S_IRUGO | S_IWUSR, \
show_temp_min, set_temp_min, offset - 1) show_temp_min, set_temp_min, offset - 1)
static DEVICE_ATTR(temp1_input, S_IRUGO, show_temp0, NULL); static DEVICE_ATTR_RO(temp1_input);
static DEVICE_ATTR(temp1_max, S_IRUGO | S_IWUSR, show_temp0_max, set_temp0_max); static DEVICE_ATTR_RW(temp1_max);
static DEVICE_ATTR(temp1_max_hyst, S_IRUGO | S_IWUSR, show_temp0_min, static DEVICE_ATTR_RW(temp1_max_hyst);
set_temp0_min);
define_temperature_sysfs(2); define_temperature_sysfs(2);
define_temperature_sysfs(3); define_temperature_sysfs(3);
...@@ -603,13 +606,13 @@ define_fan_sysfs(1); ...@@ -603,13 +606,13 @@ define_fan_sysfs(1);
define_fan_sysfs(2); define_fan_sysfs(2);
/* Alarms */ /* Alarms */
static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, static ssize_t alarms_show(struct device *dev, struct device_attribute *attr,
char *buf) char *buf)
{ {
struct vt8231_data *data = vt8231_update_device(dev); struct vt8231_data *data = vt8231_update_device(dev);
return sprintf(buf, "%d\n", data->alarms); return sprintf(buf, "%d\n", data->alarms);
} }
static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); static DEVICE_ATTR_RO(alarms);
static ssize_t show_alarm(struct device *dev, struct device_attribute *attr, static ssize_t show_alarm(struct device *dev, struct device_attribute *attr,
char *buf) char *buf)
...@@ -633,13 +636,13 @@ static SENSOR_DEVICE_ATTR(in5_alarm, S_IRUGO, show_alarm, NULL, 2); ...@@ -633,13 +636,13 @@ static SENSOR_DEVICE_ATTR(in5_alarm, S_IRUGO, show_alarm, NULL, 2);
static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, 6); static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, 6);
static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 7); static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 7);
static ssize_t show_name(struct device *dev, struct device_attribute static ssize_t name_show(struct device *dev, struct device_attribute
*devattr, char *buf) *devattr, char *buf)
{ {
struct vt8231_data *data = dev_get_drvdata(dev); struct vt8231_data *data = dev_get_drvdata(dev);
return sprintf(buf, "%s\n", data->name); return sprintf(buf, "%s\n", data->name);
} }
static DEVICE_ATTR(name, S_IRUGO, show_name, NULL); static DEVICE_ATTR_RO(name);
static struct attribute *vt8231_attributes_temps[6][5] = { static struct attribute *vt8231_attributes_temps[6][5] = {
{ {
......
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