Skip to content

Commit

Permalink
hwmon: (it87) Properly handle wrong sensor type requests
Browse files Browse the repository at this point in the history
Currently, if someone tries to set the thermal sensor type to an
unsupported value, subsequent accesses to the chip may temporarily
show the sensor in question as disabled. Use a temporary variable
and only update the cached value on success, to prevent such
confusion.

Signed-off-by: Jean Delvare <khali@linux-fr.org>
  • Loading branch information
Jean Delvare committed Apr 14, 2010
1 parent a00afb9 commit 8acf07c
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions drivers/hwmon/it87.c
Original file line number Diff line number Diff line change
Expand Up @@ -539,29 +539,29 @@ static ssize_t set_sensor(struct device *dev, struct device_attribute *attr,

struct it87_data *data = dev_get_drvdata(dev);
long val;
u8 reg;

if (strict_strtol(buf, 10, &val) < 0)
return -EINVAL;

mutex_lock(&data->update_lock);

data->sensor = it87_read_value(data, IT87_REG_TEMP_ENABLE);
data->sensor &= ~(1 << nr);
data->sensor &= ~(8 << nr);
reg = it87_read_value(data, IT87_REG_TEMP_ENABLE);
reg &= ~(1 << nr);
reg &= ~(8 << nr);
if (val == 2) { /* backwards compatibility */
dev_warn(dev, "Sensor type 2 is deprecated, please use 4 "
"instead\n");
val = 4;
}
/* 3 = thermal diode; 4 = thermistor; 0 = disabled */
if (val == 3)
data->sensor |= 1 << nr;
reg |= 1 << nr;
else if (val == 4)
data->sensor |= 8 << nr;
else if (val != 0) {
mutex_unlock(&data->update_lock);
reg |= 8 << nr;
else if (val != 0)
return -EINVAL;
}

mutex_lock(&data->update_lock);
data->sensor = reg;
it87_write_value(data, IT87_REG_TEMP_ENABLE, data->sensor);
mutex_unlock(&data->update_lock);
return count;
Expand Down

0 comments on commit 8acf07c

Please sign in to comment.