diff options
author | Jean Delvare <khali@linux-fr.org> | 2010-04-14 10:14:09 -0400 |
---|---|---|
committer | Jean Delvare <khali@linux-fr.org> | 2010-04-14 10:14:09 -0400 |
commit | 8acf07c5a7674e53f2d320d540aec5d714b105cf (patch) | |
tree | 4a7f46597031fcede0c2fdd6851e353784070758 /drivers/hwmon/it87.c | |
parent | a00afb97e23fd904b12a3f4de3237d8ab2f68738 (diff) |
hwmon: (it87) Properly handle wrong sensor type requests
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>
Diffstat (limited to 'drivers/hwmon/it87.c')
-rw-r--r-- | drivers/hwmon/it87.c | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/drivers/hwmon/it87.c b/drivers/hwmon/it87.c index 5e39e2d40380..a65ba31cad29 100644 --- a/drivers/hwmon/it87.c +++ b/drivers/hwmon/it87.c | |||
@@ -539,15 +539,14 @@ static ssize_t set_sensor(struct device *dev, struct device_attribute *attr, | |||
539 | 539 | ||
540 | struct it87_data *data = dev_get_drvdata(dev); | 540 | struct it87_data *data = dev_get_drvdata(dev); |
541 | long val; | 541 | long val; |
542 | u8 reg; | ||
542 | 543 | ||
543 | if (strict_strtol(buf, 10, &val) < 0) | 544 | if (strict_strtol(buf, 10, &val) < 0) |
544 | return -EINVAL; | 545 | return -EINVAL; |
545 | 546 | ||
546 | mutex_lock(&data->update_lock); | 547 | reg = it87_read_value(data, IT87_REG_TEMP_ENABLE); |
547 | 548 | reg &= ~(1 << nr); | |
548 | data->sensor = it87_read_value(data, IT87_REG_TEMP_ENABLE); | 549 | reg &= ~(8 << nr); |
549 | data->sensor &= ~(1 << nr); | ||
550 | data->sensor &= ~(8 << nr); | ||
551 | if (val == 2) { /* backwards compatibility */ | 550 | if (val == 2) { /* backwards compatibility */ |
552 | dev_warn(dev, "Sensor type 2 is deprecated, please use 4 " | 551 | dev_warn(dev, "Sensor type 2 is deprecated, please use 4 " |
553 | "instead\n"); | 552 | "instead\n"); |
@@ -555,13 +554,14 @@ static ssize_t set_sensor(struct device *dev, struct device_attribute *attr, | |||
555 | } | 554 | } |
556 | /* 3 = thermal diode; 4 = thermistor; 0 = disabled */ | 555 | /* 3 = thermal diode; 4 = thermistor; 0 = disabled */ |
557 | if (val == 3) | 556 | if (val == 3) |
558 | data->sensor |= 1 << nr; | 557 | reg |= 1 << nr; |
559 | else if (val == 4) | 558 | else if (val == 4) |
560 | data->sensor |= 8 << nr; | 559 | reg |= 8 << nr; |
561 | else if (val != 0) { | 560 | else if (val != 0) |
562 | mutex_unlock(&data->update_lock); | ||
563 | return -EINVAL; | 561 | return -EINVAL; |
564 | } | 562 | |
563 | mutex_lock(&data->update_lock); | ||
564 | data->sensor = reg; | ||
565 | it87_write_value(data, IT87_REG_TEMP_ENABLE, data->sensor); | 565 | it87_write_value(data, IT87_REG_TEMP_ENABLE, data->sensor); |
566 | mutex_unlock(&data->update_lock); | 566 | mutex_unlock(&data->update_lock); |
567 | return count; | 567 | return count; |