Skip to content

Commit

Permalink
hwmon: (fam15h_power) Fix unintentional integer overflow
Browse files Browse the repository at this point in the history
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 <[email protected]>
Acked-by: Jean Delvare <[email protected]>
Acked-by: Andreas Herrmann <[email protected]>
  • Loading branch information
groeck committed Jul 22, 2012
1 parent 58c3667 commit 62867d4
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion drivers/hwmon/fam15h_power.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 62867d4

Please sign in to comment.