From: David Lechner Date: Thu, 11 Sep 2025 21:42:00 +0000 (-0500) Subject: iio: adc: ad7124: use clamp() X-Git-Tag: v6.18-rc1~74^2~7^2~17 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=faf7f9e72a57481448f5047bb3c7a951e9683952;p=thirdparty%2Flinux.git iio: adc: ad7124: use clamp() Use clamp() instead of open-coding clamping. Signed-off-by: David Lechner Reviewed-by: Andy Shevchenko Signed-off-by: Jonathan Cameron --- diff --git a/drivers/iio/adc/ad7124.c b/drivers/iio/adc/ad7124.c index 6f4629c4a2f04..8213f625bb3e5 100644 --- a/drivers/iio/adc/ad7124.c +++ b/drivers/iio/adc/ad7124.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -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;