Skip to contentSkip to conversation

hwmon: (acpi_power_meter) Fix unintentional integer overflow

PATCH In review Guenter Roeck 2 participants 2 messages Jul 8, 2012 Hardware monitoring

lore
Share & tools
lore

Guenter Roeck

author maintainer
#0 lore raw

PATCH v2 1/1 hwmon: (acpi_power_meter) Fix unintentional integer overflow

Expression with two integer variables is calculated as integer before it is converted to u64. This may result in an integer overflow. Fix by declaring trip point variables as s64 instead of int.

This patch addresses Coverity #200596: Unintentional integer overflow.

---
v2: Fix by declaring trip point variables as s64 instead of multiplying with
1000ULL. This is more consistent with the rest of the code.

 drivers/hwmon/acpi_power_meter.c |    4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/hwmon/acpi_power_meter.c +1 -3
index 9a0821f1..5363da5 100644
@@ -101,7 +101,7 @@ struct acpi_power_meter_resource {
 	unsigned long		sensors_last_updated;
 	struct sensor_device_attribute	sensors[NUM_SENSORS];
 	int			num_sensors;
-	int			trip[2];
+	s64			trip[2];
 	int			num_domain_devices;
 	struct acpi_device	**domain_devices;
 	struct kobject		*holders_dir;
@@ -308,8 +308,6 @@ static ssize_t set_trip(struct device *dev, struct device_attribute *devattr,
 		return res;
 
 	temp = DIV_ROUND_CLOSEST(temp, 1000);
-	if (temp > INT_MAX)
-		return -EINVAL;
 
 	mutex_lock(&resource->lock);
 	resource->trip[attr->index - 7] = temp;
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 28 lines · Guenter Roeck

Expression with two integer variables is calculated as integer before it is converted to u64. This may result in an integer overflow. Fix by declaring trip point variables as s64 instead of int.

This patch addresses Coverity #200596: Unintentional integer overflow.

---
v2: Fix by declaring trip point variables as s64 instead of multiplying with
1000ULL. This is more consistent with the rest of the code.

 drivers/hwmon/acpi_power_meter.c |    4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/hwmon/acpi_power_meter.c +1 -1
index 9a0821f1..5363da5 100644
@@ -101,7 +101,7 @@ struct acpi_power_meter_resource {
 	unsigned long		sensors_last_updated;
 	struct sensor_device_attribute	sensors[NUM_SENSORS];
 	int			num_sensors;
-	int			trip[2];
+	s64			trip[2];
 	int			num_domain_devices;
 	struct acpi_device	**domain_devices;
 	struct kobject		*holders_dir;

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

Quoted 8 lines
drivers/hwmon/acpi_power_meter.c +0 -2
@@ -308,8 +308,6 @@ static ssize_t set_trip(struct device *dev, struct device_attribute *devattr,
 		return res;
 
 	temp = DIV_ROUND_CLOSEST(temp, 1000);
-	if (temp > INT_MAX)
-		return -EINVAL;
 
 	mutex_lock(&resource->lock);
 	resource->trip[attr->index - 7] = temp;
Signature · 6 lines
Jean Delvare

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