• Axel Lin's avatar
    hwmon: (lm92) Prevent overflow problem when writing large limits · b2d64341
    Axel Lin authored
    commit 5b963089 upstream.
    
    On platforms with sizeof(int) < sizeof(long), writing a temperature
    limit larger than MAXINT will result in unpredictable limit values
    written to the chip. Avoid auto-conversion from long to int to fix
    the problem.
    
    The hysteresis temperature range depends on the value of
    data->temp[attr->index], since val is subtracted from it.
    Use a wider clamp, [-120000, 220000] should do to cover the
    possible range. Also add missing TEMP_TO_REG() on writes into
    cached hysteresis value.
    
    Also uses clamp_val to simplify the code a bit.
    Signed-off-by: default avatarAxel Lin <axel.lin@ingics.com>
    [Guenter Roeck: Fixed double TEMP_TO_REG on hysteresis updates]
    Signed-off-by: default avatarGuenter Roeck <linux@roeck-us.net>
    [bwh: Backported to 3.2:
     - s/temp\[attr->index\]/temp1_crit/
     - s/temp\[t_hyst\]/temp1_hyst/]
    Signed-off-by: default avatarBen Hutchings <ben@decadent.org.uk>
    b2d64341
lm92.c 13.1 KB