]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
iio: consumers: Add an iio_multiply_value() helper function
authorHans de Goede <hansg@kernel.org>
Sun, 31 Aug 2025 10:48:22 +0000 (12:48 +0200)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Wed, 10 Sep 2025 18:47:04 +0000 (19:47 +0100)
commitcec1aec9c46305743a2d4a1bfb06f6b0374d5ed0
tree8cbf13944593a31350122bc858af4744b0144c07
parent33f5c69c4daff39c010b3ea6da8ebab285f4277b
iio: consumers: Add an iio_multiply_value() helper function

The channel-scale handling in iio_convert_raw_to_processed() in essence
does the following:

processed  = raw * caller-provided-scale * channel-scale

Which can also be written as:

multiplier = raw * caller-provided-scale
iio-value  = channel-scale
processed  = multiplier * iio-value

Where iio-value is a set of IIO_VAL_* type + val + val2 integers, being
able to handle multiplication of iio-values like this is something
which is useful to have in general and, as previous bugfixes to
iio_convert_raw_to_processed() have shown, also tricky to implement.

Split the iio-value multiplication code from iio_convert_raw_to_processed()
out into a new iio_multiply_value() helper. This serves multiple purposes:

1. Having this split out allows writing a KUnit test for this.
2. Having this split out allows re-use to get better precision
   when scaling values in iio_read_channel_processed_scale().

Reviewed-by: Andy Shevchenko <andy@kernel.org>
Signed-off-by: Hans de Goede <hansg@kernel.org>
Link: https://patch.msgid.link/20250831104825.15097-4-hansg@kernel.org
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/inkern.c
include/linux/iio/consumer.h