]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
hwmon: iio: Use iio_read_channel_processed_scale for IIO_POWER
authorSean Anderson <sean.anderson@linux.dev>
Thu, 20 Jun 2024 21:20:05 +0000 (17:20 -0400)
committerGuenter Roeck <linux@roeck-us.net>
Fri, 21 Jun 2024 15:09:32 +0000 (08:09 -0700)
Instead of rescaling power channels after the fact, use the dedicated
scaling API. This should reduce any inaccuracies resulting from the
scaling.

Signed-off-by: Sean Anderson <sean.anderson@linux.dev>
Link: https://lore.kernel.org/r/20240620212005.821805-1-sean.anderson@linux.dev
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
drivers/hwmon/iio_hwmon.c

index 4c8a8084789127843516b4eb2417805ea70022da..fab32e1e15f2c8e0d7ad8a46fe9fc22a719b8177 100644 (file)
@@ -49,16 +49,17 @@ static ssize_t iio_hwmon_read_val(struct device *dev,
        struct iio_channel *chan = &state->channels[sattr->index];
        enum iio_chan_type type;
 
-       ret = iio_read_channel_processed(chan, &result);
-       if (ret < 0)
-               return ret;
-
        ret = iio_get_channel_type(chan, &type);
        if (ret < 0)
                return ret;
 
        if (type == IIO_POWER)
-               result *= 1000; /* mili-Watts to micro-Watts conversion */
+               /* mili-Watts to micro-Watts conversion */
+               ret = iio_read_channel_processed_scale(chan, &result, 1000);
+       else
+               ret = iio_read_channel_processed(chan, &result);
+       if (ret < 0)
+               return ret;
 
        return sprintf(buf, "%d\n", result);
 }