• Guenter Roeck's avatar
    hwmon: (ntc_thermistor) Optimize and fix build warning · dbe43a62
    Guenter Roeck authored
    The following build warning is seen in some configurations:
    
    drivers/hwmon/ntc_thermistor.c: In function 'ntc_show_temp':
    drivers/hwmon/ntc_thermistor.c:293: warning: 'temp' may be used uninitialized in this function
    
    Fix the problem by re-arranging the code to overload return values with error
    codes, and by avoiding error returns whenever possible.
    
    Specifically,
    
    Simplify lookup_comp() to not return an error. Instead, return i_low == i_high
    if there is an exact match, or if the ohm value is outside the lookup table
    range.
    
    Modify get_temp_mC() to not return an error. Since it only returns an error
    after lookup_comp() returned an error, this is quite straightforward after above
    change.
    
    Separate ntc_thermistor_read() into a function to read the resistor value (which
    can return an error), and the call to get_temp_mC() which doesn't. Call the
    functions directly from ntc_show_temp().
    
    Code was tested using a test program, comparing the result of the old and new
    versions of get_temp_mC() for resistor values between 0 and 2,000,000 ohm.
    
    As a side effect, this patch reduces code size by approximately 400 bytes on
    x86_64.
    Signed-off-by: default avatarGuenter Roeck <guenter.roeck@ericsson.com>
    Cc: Donggeun Kim <dg77.kim@samsung.com>
    Reviewed-by: default avatarRobert Coulson <robert.coulson@ericsson.com>
    dbe43a62
ntc_thermistor.c 11.6 KB