Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

hwmon: (sht3x) Fix error handling

Handling of errors when reading status, temperature, and humidity returns
the error number as negative attribute value. Fix it up by returning
the error as return value.

Fixes: a0ac418c6007c ("hwmon: (sht3x) convert some of sysfs interface to hwmon")
Cc: JuenKit Yip <JuenKit_Yip@hotmail.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>

+17 -10
+17 -10
drivers/hwmon/sht3x.c
··· 291 291 return data; 292 292 } 293 293 294 - static int temp1_input_read(struct device *dev) 294 + static int temp1_input_read(struct device *dev, long *temp) 295 295 { 296 296 struct sht3x_data *data = sht3x_update_client(dev); 297 297 298 298 if (IS_ERR(data)) 299 299 return PTR_ERR(data); 300 300 301 - return data->temperature; 301 + *temp = data->temperature; 302 + return 0; 302 303 } 303 304 304 - static int humidity1_input_read(struct device *dev) 305 + static int humidity1_input_read(struct device *dev, long *humidity) 305 306 { 306 307 struct sht3x_data *data = sht3x_update_client(dev); 307 308 308 309 if (IS_ERR(data)) 309 310 return PTR_ERR(data); 310 311 311 - return data->humidity; 312 + *humidity = data->humidity; 313 + return 0; 312 314 } 313 315 314 316 /* ··· 708 706 u32 attr, int channel, long *val) 709 707 { 710 708 enum sht3x_limits index; 709 + int ret; 711 710 712 711 switch (type) { 713 712 case hwmon_chip: ··· 723 720 case hwmon_temp: 724 721 switch (attr) { 725 722 case hwmon_temp_input: 726 - *val = temp1_input_read(dev); 727 - break; 723 + return temp1_input_read(dev, val); 728 724 case hwmon_temp_alarm: 729 - *val = temp1_alarm_read(dev); 725 + ret = temp1_alarm_read(dev); 726 + if (ret < 0) 727 + return ret; 728 + *val = ret; 730 729 break; 731 730 case hwmon_temp_max: 732 731 index = limit_max; ··· 753 748 case hwmon_humidity: 754 749 switch (attr) { 755 750 case hwmon_humidity_input: 756 - *val = humidity1_input_read(dev); 757 - break; 751 + return humidity1_input_read(dev, val); 758 752 case hwmon_humidity_alarm: 759 - *val = humidity1_alarm_read(dev); 753 + ret = humidity1_alarm_read(dev); 754 + if (ret < 0) 755 + return ret; 756 + *val = ret; 760 757 break; 761 758 case hwmon_humidity_max: 762 759 index = limit_max;