Skip to content

Commit

Permalink
hwmon: (dme1737) fix divide-by-0
Browse files Browse the repository at this point in the history
This patch fixes a possible divide-by-0 and a minor bug in the
FAN_FROM_REG macro (in TPC mode).

Signed-off-by: Juerg Haefliger <juergh at gmail.com>
Acked-by: Jean Delvare <khali@linux-fr.org>
Signed-off-by: Mark M. Hoffman <mhoffman@lightlink.com>
  • Loading branch information
Juerg Haefliger authored and Mark M. Hoffman committed Feb 8, 2008
1 parent cb96b8c commit ff8421f
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions drivers/hwmon/dme1737.c
Original file line number Diff line number Diff line change
Expand Up @@ -283,14 +283,21 @@ static inline int TEMP_HYST_TO_REG(int val, int ix, int reg)
/* Fan input RPM */
static inline int FAN_FROM_REG(int reg, int tpc)
{
return (reg == 0 || reg == 0xffff) ? 0 :
(tpc == 0) ? 90000 * 60 / reg : tpc * reg;
if (tpc) {
return tpc * reg;
} else {
return (reg == 0 || reg == 0xffff) ? 0 : 90000 * 60 / reg;
}
}

static inline int FAN_TO_REG(int val, int tpc)
{
return SENSORS_LIMIT((tpc == 0) ? 90000 * 60 / val : val / tpc,
0, 0xffff);
if (tpc) {
return SENSORS_LIMIT(val / tpc, 0, 0xffff);
} else {
return (val <= 0) ? 0xffff :
SENSORS_LIMIT(90000 * 60 / val, 0, 0xfffe);
}
}

/* Fan TPC (tach pulse count)
Expand Down

0 comments on commit ff8421f

Please sign in to comment.