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: a0ac418c60 ("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>
pull/1354/merge
Guenter Roeck 2025-10-18 06:04:57 -07:00
parent a09a5aa8bf
commit 8dcc66ad37
1 changed files with 17 additions and 10 deletions

View File

@ -291,24 +291,26 @@ out:
return data; return data;
} }
static int temp1_input_read(struct device *dev) static int temp1_input_read(struct device *dev, long *temp)
{ {
struct sht3x_data *data = sht3x_update_client(dev); struct sht3x_data *data = sht3x_update_client(dev);
if (IS_ERR(data)) if (IS_ERR(data))
return PTR_ERR(data); return PTR_ERR(data);
return data->temperature; *temp = data->temperature;
return 0;
} }
static int humidity1_input_read(struct device *dev) static int humidity1_input_read(struct device *dev, long *humidity)
{ {
struct sht3x_data *data = sht3x_update_client(dev); struct sht3x_data *data = sht3x_update_client(dev);
if (IS_ERR(data)) if (IS_ERR(data))
return PTR_ERR(data); return PTR_ERR(data);
return data->humidity; *humidity = data->humidity;
return 0;
} }
/* /*
@ -706,6 +708,7 @@ static int sht3x_read(struct device *dev, enum hwmon_sensor_types type,
u32 attr, int channel, long *val) u32 attr, int channel, long *val)
{ {
enum sht3x_limits index; enum sht3x_limits index;
int ret;
switch (type) { switch (type) {
case hwmon_chip: case hwmon_chip:
@ -720,10 +723,12 @@ static int sht3x_read(struct device *dev, enum hwmon_sensor_types type,
case hwmon_temp: case hwmon_temp:
switch (attr) { switch (attr) {
case hwmon_temp_input: case hwmon_temp_input:
*val = temp1_input_read(dev); return temp1_input_read(dev, val);
break;
case hwmon_temp_alarm: case hwmon_temp_alarm:
*val = temp1_alarm_read(dev); ret = temp1_alarm_read(dev);
if (ret < 0)
return ret;
*val = ret;
break; break;
case hwmon_temp_max: case hwmon_temp_max:
index = limit_max; index = limit_max;
@ -748,10 +753,12 @@ static int sht3x_read(struct device *dev, enum hwmon_sensor_types type,
case hwmon_humidity: case hwmon_humidity:
switch (attr) { switch (attr) {
case hwmon_humidity_input: case hwmon_humidity_input:
*val = humidity1_input_read(dev); return humidity1_input_read(dev, val);
break;
case hwmon_humidity_alarm: case hwmon_humidity_alarm:
*val = humidity1_alarm_read(dev); ret = humidity1_alarm_read(dev);
if (ret < 0)
return ret;
*val = ret;
break; break;
case hwmon_humidity_max: case hwmon_humidity_max:
index = limit_max; index = limit_max;