Commit 27c4db39 authored by Guenter Roeck's avatar Guenter Roeck

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: default avatarGuenter Roeck <linux@roeck-us.net>
Acked-by: default avatarJean Delvare <khali@linux-fr.org>
parent 27f8b135
...@@ -237,7 +237,7 @@ static ssize_t set_cap(struct device *dev, struct device_attribute *devattr, ...@@ -237,7 +237,7 @@ static ssize_t set_cap(struct device *dev, struct device_attribute *devattr,
if (res) if (res)
return res; return res;
temp /= 1000; temp = DIV_ROUND_CLOSEST(temp, 1000);
if (temp > resource->caps.max_cap || temp < resource->caps.min_cap) if (temp > resource->caps.max_cap || temp < resource->caps.min_cap)
return -EINVAL; return -EINVAL;
arg0.integer.value = temp; arg0.integer.value = temp;
...@@ -307,8 +307,8 @@ static ssize_t set_trip(struct device *dev, struct device_attribute *devattr, ...@@ -307,8 +307,8 @@ static ssize_t set_trip(struct device *dev, struct device_attribute *devattr,
if (res) if (res)
return res; return res;
temp /= 1000; temp = DIV_ROUND_CLOSEST(temp, 1000);
if (temp < 0) if (temp > INT_MAX)
return -EINVAL; return -EINVAL;
mutex_lock(&resource->lock); mutex_lock(&resource->lock);
......
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