Skip to contentSkip to conversation

hwmon: (acpi_power_meter) Cleanup and optimizations

PATCH In review Guenter Roeck 2 participants 2 messages Jun 21, 2012 Hardware monitoring

lore
Share & tools
lore

Guenter Roeck

author maintainer
#0 lore raw

PATCH v2 1/1 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

---

v2: Use DIV_ROUND_CLOSEST
Return error if entered temperature is larger than INT_MAX
Notes: Did not use clamping since driver elsewhere returns errors for out-of-range values.
Further limit checks are done by ACPI code.

 drivers/hwmon/acpi_power_meter.c |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/hwmon/acpi_power_meter.c +3 -3
index 34ad5a2..9a0821f1 100644
@@ -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;
@@ -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);
Signature · 7 lines
1.7.9.7


_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Acked-by on v2 1/1
#1 lore raw
Quoted 31 lines · Guenter Roeck

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

---

v2: Use DIV_ROUND_CLOSEST
Return error if entered temperature is larger than INT_MAX
Notes: Did not use clamping since driver elsewhere returns errors for out-of-range values.
Further limit checks are done by ACPI code.

 drivers/hwmon/acpi_power_meter.c |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/hwmon/acpi_power_meter.c +1 -1
index 34ad5a2..9a0821f1 100644
@@ -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;

drivers/hwmon/acpi_power_meter.c static ssize_t set_trip(struct device *dev, struct device_attribute *devattr, · line 314

Quoted 10 lines
drivers/hwmon/acpi_power_meter.c +2 -2
@@ -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);
Signature · 6 lines
Jean Delvare

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors