]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
hwmon: (sht3x) Fix error handling
authorGuenter Roeck <linux@roeck-us.net>
Sat, 18 Oct 2025 13:04:57 +0000 (06:04 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 29 Oct 2025 13:08:59 +0000 (14:08 +0100)
[ Upstream commit 8dcc66ad379ec0642fb281c45ccfd7d2d366e53f ]

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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/hwmon/sht3x.c

index 650b0bcc2359eed7a127835eb17300c58541fc5c..94466e28dc56f3716bd3bff21118c22d95adb83e 100644 (file)
@@ -294,24 +294,26 @@ out:
        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);
 
        if (IS_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);
 
        if (IS_ERR(data))
                return PTR_ERR(data);
 
-       return data->humidity;
+       *humidity = data->humidity;
+       return 0;
 }
 
 /*
@@ -709,6 +711,7 @@ static int sht3x_read(struct device *dev, enum hwmon_sensor_types type,
                      u32 attr, int channel, long *val)
 {
        enum sht3x_limits index;
+       int ret;
 
        switch (type) {
        case hwmon_chip:
@@ -723,10 +726,12 @@ static int sht3x_read(struct device *dev, enum hwmon_sensor_types type,
        case hwmon_temp:
                switch (attr) {
                case hwmon_temp_input:
-                       *val = temp1_input_read(dev);
-                       break;
+                       return temp1_input_read(dev, val);
                case hwmon_temp_alarm:
-                       *val = temp1_alarm_read(dev);
+                       ret = temp1_alarm_read(dev);
+                       if (ret < 0)
+                               return ret;
+                       *val = ret;
                        break;
                case hwmon_temp_max:
                        index = limit_max;
@@ -751,10 +756,12 @@ static int sht3x_read(struct device *dev, enum hwmon_sensor_types type,
        case hwmon_humidity:
                switch (attr) {
                case hwmon_humidity_input:
-                       *val = humidity1_input_read(dev);
-                       break;
+                       return humidity1_input_read(dev, val);
                case hwmon_humidity_alarm:
-                       *val = humidity1_alarm_read(dev);
+                       ret = humidity1_alarm_read(dev);
+                       if (ret < 0)
+                               return ret;
+                       *val = ret;
                        break;
                case hwmon_humidity_max:
                        index = limit_max;