Skip to content

Commit

Permalink
hwmon: (acpi_power_meter) Fix unintentional integer overflow
Browse files Browse the repository at this point in the history
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.

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 27c4db3 commit 75311be
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions drivers/hwmon/acpi_power_meter.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 75311be

Please sign in to comment.