• Guenter Roeck's avatar
    hwmon: (lm85) Fix various errors on attribute writes · d02ae215
    Guenter Roeck authored
    commit 3248c3b7 upstream.
    
    Temperature limit register writes did not account for negative numbers.
    As a result, writing -127000 resulted in -126000 written into the
    temperature limit register. This problem affected temp[1-3]_min,
    temp[1-3]_max, temp[1-3]_auto_temp_crit, and temp[1-3]_auto_temp_min.
    
    When writing pwm[1-3]_freq, a long variable was auto-converted into an int
    without range check. Wiring values larger than MAXINT resulted in unexpected
    register values.
    
    When writing temp[1-3]_auto_temp_max, an unsigned long variable was
    auto-converted into an int without range check. Writing values larger than
    MAXINT resulted in unexpected register values.
    
    vrm is an u8, so the written value needs to be limited to [0, 255].
    
    Cc: Axel Lin <axel.lin@ingics.com>
    Reviewed-by: default avatarAxel Lin <axel.lin@ingics.com>
    Signed-off-by: default avatarGuenter Roeck <linux@roeck-us.net>
    [bwh: Backported to 3.2:
     - Driver is not using clamp_val(); keep using SENSORS_LIMIT() for consistency
     - Driver is not using kstrtoul(); make the minimum change to store_vrm_reg()
       so we can validate the value before assigning]
    Signed-off-by: default avatarBen Hutchings <ben@decadent.org.uk>
    d02ae215
lm85.c 48.6 KB