]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
iio: adc: ad7124: use clamp()
authorDavid Lechner <dlechner@baylibre.com>
Thu, 11 Sep 2025 21:42:00 +0000 (16:42 -0500)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Sat, 13 Sep 2025 13:37:59 +0000 (14:37 +0100)
Use clamp() instead of open-coding clamping.

Signed-off-by: David Lechner <dlechner@baylibre.com>
Reviewed-by: Andy Shevchenko <andy@kernel.org>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/adc/ad7124.c

index 6f4629c4a2f04a39d3e30607e6f4de0dba799e4a..8213f625bb3e5fd1917d161804274f4c49d52130 100644 (file)
@@ -15,6 +15,7 @@
 #include <linux/interrupt.h>
 #include <linux/kernel.h>
 #include <linux/kfifo.h>
+#include <linux/minmax.h>
 #include <linux/module.h>
 #include <linux/mod_devicetable.h>
 #include <linux/property.h>
@@ -299,11 +300,7 @@ static void ad7124_set_channel_odr(struct ad7124_state *st, unsigned int channel
         * FS[10:0] can have a value from 1 to 2047
         */
        factor = 32 * 4; /* N = 4 for default sinc4 filter. */
-       odr_sel_bits = DIV_ROUND_CLOSEST(fclk, odr * factor);
-       if (odr_sel_bits < 1)
-               odr_sel_bits = 1;
-       else if (odr_sel_bits > 2047)
-               odr_sel_bits = 2047;
+       odr_sel_bits = clamp(DIV_ROUND_CLOSEST(fclk, odr * factor), 1, 2047);
 
        if (odr_sel_bits != st->channels[channel].cfg.odr_sel_bits)
                st->channels[channel].cfg.live = false;