From: Juerg Haefliger Date: Mon, 28 Jan 2008 00:39:46 +0000 (-0800) Subject: hwmon: (dme1737) fix divide-by-0 X-Git-Tag: v2.6.25-rc1~281^2~12 X-Git-Url: http://pilppa.com/gitweb/?a=commitdiff_plain;h=ff8421f733c91a70d8edadf9ce2842fca66172fa;p=linux-2.6-omap-h63xx.git hwmon: (dme1737) fix divide-by-0 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 Acked-by: Jean Delvare Signed-off-by: Mark M. Hoffman --- diff --git a/drivers/hwmon/dme1737.c b/drivers/hwmon/dme1737.c index 85064fb0b7c..307f48de051 100644 --- a/drivers/hwmon/dme1737.c +++ b/drivers/hwmon/dme1737.c @@ -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)