mirror of
https://github.com/team-infusion-developers/android_kernel_samsung_msm8976.git
synced 2024-11-07 04:09:21 +00:00
hwmon: Prevent some divide by zeros in FAN_TO_REG()
commit 3806b45ba4655147a011df03242cc197ab986c43 upstream. The "rpm * div" operations can overflow here, so this patch adds an upper limit to rpm to prevent that. Jean Delvare helped me with this patch. Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com> Acked-by: Roger Lucas <vt8231@hiddenengine.co.uk> Signed-off-by: Jean Delvare <khali@linux-fr.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
e77a822f21
commit
223cc81c8c
3 changed files with 5 additions and 1 deletions
|
@ -94,6 +94,8 @@ static inline u8 FAN_TO_REG(long rpm, int div)
|
|||
{
|
||||
if (rpm <= 0)
|
||||
return 255;
|
||||
if (rpm > 1350000)
|
||||
return 1;
|
||||
return clamp_val((1350000 + rpm * div / 2) / (rpm * div), 1, 254);
|
||||
}
|
||||
|
||||
|
|
|
@ -141,6 +141,8 @@ static inline u8 FAN_TO_REG(long rpm, int div)
|
|||
{
|
||||
if (rpm <= 0)
|
||||
return 255;
|
||||
if (rpm > 1350000)
|
||||
return 1;
|
||||
return clamp_val((1350000 + rpm * div / 2) / (rpm * div), 1, 254);
|
||||
}
|
||||
|
||||
|
|
|
@ -145,7 +145,7 @@ static const u8 regtempmin[] = { 0x3a, 0x3e, 0x2c, 0x2e, 0x30, 0x32 };
|
|||
*/
|
||||
static inline u8 FAN_TO_REG(long rpm, int div)
|
||||
{
|
||||
if (rpm == 0)
|
||||
if (rpm <= 0 || rpm > 1310720)
|
||||
return 0;
|
||||
return clamp_val(1310720 / (rpm * div), 1, 255);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue