]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commitdiff
hwmon: (fam15h_power) Fix unintentional integer overflow
authorGuenter Roeck <linux@roeck-us.net>
Thu, 21 Jun 2012 13:26:12 +0000 (06:26 -0700)
committerGuenter Roeck <linux@roeck-us.net>
Sun, 22 Jul 2012 04:48:28 +0000 (21:48 -0700)
Expression with two unsigned integer variables is calculated as unsigned integer
before it is converted to u64. This may result in an integer overflow.
Fix by typecasting the left operand to u64 before performing the left shift.

This patch addresses Coverity #402320: Unintentional integer overflow.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Acked-by: Jean Delvare <khali@linux-fr.org>
Acked-by: Andreas Herrmann <andreas.herrmann3@amd.com>
drivers/hwmon/fam15h_power.c

index 6b13f1a4dc27c1d9fb48a6d0edc5fb46de83918b..2764b78a784b9be83f9df1fd48f558452d9b8d61 100644 (file)
@@ -67,7 +67,8 @@ static ssize_t show_power(struct device *dev,
                                  REG_TDP_LIMIT3, &val);
 
        tdp_limit = val >> 16;
-       curr_pwr_watts = (tdp_limit + data->base_tdp) << running_avg_range;
+       curr_pwr_watts = ((u64)(tdp_limit +
+                               data->base_tdp)) << running_avg_range;
        curr_pwr_watts -= running_avg_capture;
        curr_pwr_watts *= data->tdp_to_watts;