lkml.org 
[lkml]   [2013]   [Dec]   [17]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[PATCH 3.5 094/103] hwmon: Prevent some divide by zeros in FAN_TO_REG()
    Date
    3.5.7.28 -stable review patch.  If anyone has any objections, please let me know.

    ------------------

    From: Dan Carpenter <dan.carpenter@oracle.com>

    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>
    [ luis: backported to 3.5: adjusted context ]
    Signed-off-by: Luis Henriques <luis.henriques@canonical.com>
    ---
    drivers/hwmon/lm78.c | 2 ++
    drivers/hwmon/sis5595.c | 2 ++
    drivers/hwmon/vt8231.c | 2 +-
    3 files changed, 5 insertions(+), 1 deletion(-)

    diff --git a/drivers/hwmon/lm78.c b/drivers/hwmon/lm78.c
    index f6bc414..8d6a133 100644
    --- a/drivers/hwmon/lm78.c
    +++ b/drivers/hwmon/lm78.c
    @@ -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);
    }

    diff --git a/drivers/hwmon/sis5595.c b/drivers/hwmon/sis5595.c
    index 6c4d8eb..098489c 100644
    --- a/drivers/hwmon/sis5595.c
    +++ b/drivers/hwmon/sis5595.c
    @@ -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);
    }

    diff --git a/drivers/hwmon/vt8231.c b/drivers/hwmon/vt8231.c
    index 386a845..0a287e0 100644
    --- a/drivers/hwmon/vt8231.c
    +++ b/drivers/hwmon/vt8231.c
    @@ -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);
    }
    --
    1.8.3.2


    \
     
     \ /
      Last update: 2013-12-17 20:01    [W:4.049 / U:0.488 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site