]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
hwmon: Prevent some divide by zeros in FAN_TO_REG()
authorDan Carpenter <dan.carpenter@oracle.com>
Thu, 12 Dec 2013 07:05:33 +0000 (08:05 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 14 Apr 2014 13:44:31 +0000 (06:44 -0700)
commit 3806b45ba4655147a011df03242cc197ab986c43 upstream.

The "rpm * div" operations can overflow here, so this patch adds an
upper limit to rpm to prevent that.  Jean Delvare helped me with this
patch.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Roger Lucas <vt8231@hiddenengine.co.uk>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
[bwh: Backported to 3.2: adjust context]
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
Cc: Qiang Huang <h.huangqiang@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/hwmon/lm78.c
drivers/hwmon/sis5595.c
drivers/hwmon/vt8231.c

index f6bc414e1e91eebb256837074996545ca781d2b1..8d6a133e4d877c7e901067badf6cdb5cbb153846 100644 (file)
@@ -94,6 +94,8 @@ static inline u8 FAN_TO_REG(long rpm, int div)
 {
        if (rpm <= 0)
                return 255;
+       if (rpm > 1350000)
+               return 1;
        return SENSORS_LIMIT((1350000 + rpm * div / 2) / (rpm * div), 1, 254);
 }
 
index 6c4d8eb9b7ca5414a2d7a9f8af94e45b638e0f9d..098489cefc57f1033c9c8ae7a4c42a8287c937b9 100644 (file)
@@ -141,6 +141,8 @@ static inline u8 FAN_TO_REG(long rpm, int div)
 {
        if (rpm <= 0)
                return 255;
+       if (rpm > 1350000)
+               return 1;
        return SENSORS_LIMIT((1350000 + rpm * div / 2) / (rpm * div), 1, 254);
 }
 
index 386a845380107f3e8e7e43093764e7a92bc45634..0a287e023603b949ac4343af76658fa615e5a3d9 100644 (file)
@@ -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 <= 0 || rpm > 1310720)
                return 0;
        return SENSORS_LIMIT(1310720 / (rpm * div), 1, 255);
 }