Skip to content

Commit

Permalink
hwmon: (acpi_power_meter) Cleanup and optimizations
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Guenter Roeck committed Jul 22, 2012
1 parent 27f8b13 commit 27c4db3
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions drivers/hwmon/acpi_power_meter.c
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ static ssize_t set_cap(struct device *dev, struct device_attribute *devattr,
if (res)
return res;

temp /= 1000;
temp = DIV_ROUND_CLOSEST(temp, 1000);
if (temp > resource->caps.max_cap || temp < resource->caps.min_cap)
return -EINVAL;
arg0.integer.value = temp;
Expand Down Expand Up @@ -307,8 +307,8 @@ static ssize_t set_trip(struct device *dev, struct device_attribute *devattr,
if (res)
return res;

temp /= 1000;
if (temp < 0)
temp = DIV_ROUND_CLOSEST(temp, 1000);
if (temp > INT_MAX)
return -EINVAL;

mutex_lock(&resource->lock);
Expand Down

0 comments on commit 27c4db3

Please sign in to comment.