Gitweb:     
http://git.kernel.org/git/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=ff8421f733c91a70d8edadf9ce2842fca66172fa
Commit:     ff8421f733c91a70d8edadf9ce2842fca66172fa
Parent:     cb96b8ca11644ee1223e0fb3f1f629ead15203cb
Author:     Juerg Haefliger <[EMAIL PROTECTED]>
AuthorDate: Sun Jan 27 16:39:46 2008 -0800
Committer:  Mark M. Hoffman <[EMAIL PROTECTED]>
CommitDate: Thu Feb 7 20:39:44 2008 -0500

    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 <[EMAIL PROTECTED]>
    Signed-off-by: Mark M. Hoffman <[EMAIL PROTECTED]>
---
 drivers/hwmon/dme1737.c |   15 +++++++++++----
 1 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/drivers/hwmon/dme1737.c b/drivers/hwmon/dme1737.c
index 85064fb..307f48d 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)
-
To unsubscribe from this list: send the line "unsubscribe git-commits-head" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to