hwmon: prevent some divide by zeros in FAN_TO_REG()
Quoted 19 lines · Dan Carpenter
It's not enough to just test if "rpm" is zero, the "rpm * div" operation
could overflow and that could also lead to a divide by zero.Signed-off-by Dan Carpenter <[email protected]>drivers/hwmon/vt8231.c +1
-1@@ -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 * div =0 )return 0 ;return clamp_val (1310720 / (rpm * div),1 ,255 );
Quoted 1 line
}
Seems a reasonable improvement to me, so ACK'd.
Quoted 2 lines
drivers/hwmon/lm78.c +0
-0
SNIP
drivers/hwmon/lm78.c
Quoted 3 lines
drivers/hwmon/lm78.c +0
-0return 255 ;return clamp_val ((1350000 + rpm * div /2 ) / (rpm * div),1 ,254 ); }
- Roger