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 <juergh at gmail.com>
Acked-by: Jean Delvare <khali@linux-fr.org>
Signed-off-by: Mark M. Hoffman <mhoffman@lightlink.com>

authored by Juerg Haefliger and committed by Mark M. Hoffman ff8421f7 cb96b8ca

+11 -4
+11 -4
drivers/hwmon/dme1737.c
··· 283 /* Fan input RPM */ 284 static inline int FAN_FROM_REG(int reg, int tpc) 285 { 286 - return (reg == 0 || reg == 0xffff) ? 0 : 287 - (tpc == 0) ? 90000 * 60 / reg : tpc * reg; 288 } 289 290 static inline int FAN_TO_REG(int val, int tpc) 291 { 292 - return SENSORS_LIMIT((tpc == 0) ? 90000 * 60 / val : val / tpc, 293 - 0, 0xffff); 294 } 295 296 /* Fan TPC (tach pulse count)
··· 283 /* Fan input RPM */ 284 static inline int FAN_FROM_REG(int reg, int tpc) 285 { 286 + if (tpc) { 287 + return tpc * reg; 288 + } else { 289 + return (reg == 0 || reg == 0xffff) ? 0 : 90000 * 60 / reg; 290 + } 291 } 292 293 static inline int FAN_TO_REG(int val, int tpc) 294 { 295 + if (tpc) { 296 + return SENSORS_LIMIT(val / tpc, 0, 0xffff); 297 + } else { 298 + return (val <= 0) ? 0xffff : 299 + SENSORS_LIMIT(90000 * 60 / val, 0, 0xfffe); 300 + } 301 } 302 303 /* Fan TPC (tach pulse count)