diff options
author | Guenter Roeck <linux@roeck-us.net> | 2012-06-19 01:37:13 -0400 |
---|---|---|
committer | Guenter Roeck <linux@roeck-us.net> | 2012-07-22 00:48:44 -0400 |
commit | 27c4db3996ef0d27fb25e6991ebf6e507a920937 (patch) | |
tree | bac3effb30b62185d86cb1f36a98eec7204a17f6 /drivers/hwmon | |
parent | 27f8b1355504744e7cfbb5756f120734d58644a8 (diff) |
hwmon: (acpi_power_meter) Cleanup and optimizations
An unsigned value can not be smaller than 0. Remove the check for it.
Use DIV_ROUND_CLOSEST for divide operations converting milli-degrees C into
degrees C. Limit maximum accepted trip point temperature to INT_MAX.
This patch fixes Coverity #115214: Unsigned compared against 0
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Acked-by: Jean Delvare <khali@linux-fr.org>
Diffstat (limited to 'drivers/hwmon')
-rw-r--r-- | drivers/hwmon/acpi_power_meter.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c index 34ad5a27a7e9..9a0821f1c914 100644 --- a/drivers/hwmon/acpi_power_meter.c +++ b/drivers/hwmon/acpi_power_meter.c | |||
@@ -237,7 +237,7 @@ static ssize_t set_cap(struct device *dev, struct device_attribute *devattr, | |||
237 | if (res) | 237 | if (res) |
238 | return res; | 238 | return res; |
239 | 239 | ||
240 | temp /= 1000; | 240 | temp = DIV_ROUND_CLOSEST(temp, 1000); |
241 | if (temp > resource->caps.max_cap || temp < resource->caps.min_cap) | 241 | if (temp > resource->caps.max_cap || temp < resource->caps.min_cap) |
242 | return -EINVAL; | 242 | return -EINVAL; |
243 | arg0.integer.value = temp; | 243 | arg0.integer.value = temp; |
@@ -307,8 +307,8 @@ static ssize_t set_trip(struct device *dev, struct device_attribute *devattr, | |||
307 | if (res) | 307 | if (res) |
308 | return res; | 308 | return res; |
309 | 309 | ||
310 | temp /= 1000; | 310 | temp = DIV_ROUND_CLOSEST(temp, 1000); |
311 | if (temp < 0) | 311 | if (temp > INT_MAX) |
312 | return -EINVAL; | 312 | return -EINVAL; |
313 | 313 | ||
314 | mutex_lock(&resource->lock); | 314 | mutex_lock(&resource->lock); |