iio: temp: maxim_thermocouple: Switch to sparse friendly iio_device_claim/release_dir...
authorJonathan Cameron <Jonathan.Cameron@huawei.com>
Mon, 31 Mar 2025 12:13:14 +0000 (13:13 +0100)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Tue, 22 Apr 2025 18:10:01 +0000 (19:10 +0100)
These new functions allow sparse to find failures to release
direct mode reducing chances of bugs over the claim_direct_mode()
functions that are deprecated.

Tidy up a few direct returns whilst here.

Reviewed-by: David Lechner <dlechner@baylibre.com>
Reviewed-by: Marcelo Schmitt <marcelo.schmitt1@gmail.com>
Link: https://patch.msgid.link/20250331121317.1694135-35-jic23@kernel.org
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/temperature/maxim_thermocouple.c

index c28a7a6dea5f125ddd1d37b76a478d5b5266d27b..a1c213d5c469f3d03e04861ec8a17e7c1a4c9a4f 100644 (file)
@@ -183,40 +183,35 @@ static int maxim_thermocouple_read_raw(struct iio_dev *indio_dev,
                                       int *val, int *val2, long mask)
 {
        struct maxim_thermocouple_data *data = iio_priv(indio_dev);
-       int ret = -EINVAL;
+       int ret;
 
        switch (mask) {
        case IIO_CHAN_INFO_RAW:
-               ret = iio_device_claim_direct_mode(indio_dev);
-               if (ret)
-                       return ret;
+               if (!iio_device_claim_direct(indio_dev))
+                       return -EBUSY;
 
                ret = maxim_thermocouple_read(data, chan, val);
-               iio_device_release_direct_mode(indio_dev);
-
-               if (!ret)
-                       return IIO_VAL_INT;
+               iio_device_release_direct(indio_dev);
+               if (ret)
+                       return ret;
 
-               break;
+               return IIO_VAL_INT;
        case IIO_CHAN_INFO_SCALE:
                switch (chan->channel2) {
                case IIO_MOD_TEMP_AMBIENT:
                        *val = 62;
                        *val2 = 500000; /* 1000 * 0.0625 */
-                       ret = IIO_VAL_INT_PLUS_MICRO;
-                       break;
+                       return IIO_VAL_INT_PLUS_MICRO;
                default:
                        *val = 250; /* 1000 * 0.25 */
-                       ret = IIO_VAL_INT;
+                       return IIO_VAL_INT;
                }
-               break;
        case IIO_CHAN_INFO_THERMOCOUPLE_TYPE:
                *val = data->tc_type;
-               ret = IIO_VAL_CHAR;
-               break;
+               return IIO_VAL_CHAR;
+       default:
+               return -EINVAL;
        }
-
-       return ret;
 }
 
 static const struct iio_info maxim_thermocouple_info = {