[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250907110225.01a6341e@jic23-huawei>
Date: Sun, 7 Sep 2025 11:02:25 +0100
From: Jonathan Cameron <jic23@...nel.org>
To: David Lechner <dlechner@...libre.com>
Cc: Michael Hennerich <Michael.Hennerich@...log.com>, Nuno Sá
<nuno.sa@...log.com>, Andy Shevchenko <andy@...nel.org>,
linux-iio@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH 1/6] iio: adc: ad7124: use clamp()
On Fri, 05 Sep 2025 13:11:56 -0500
David Lechner <dlechner@...libre.com> wrote:
> Use clamp() instead of open-coding clamping.
>
> Signed-off-by: David Lechner <dlechner@...libre.com>
Good tidy up on it's own so I'll pick this up now.
I haven't read the rest yet but I'd imagine others will need
more review than this.
Applied this patch to the togreg branch of iio.git and pushed out as testing.
> ---
> drivers/iio/adc/ad7124.c | 7 ++-----
> 1 file changed, 2 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/iio/adc/ad7124.c b/drivers/iio/adc/ad7124.c
> index 70f458e3ccc12db884dda9003abcffdf48989e5e..117777fc8ad05b773da09c113cf84927c75d6b7b 100644
> --- a/drivers/iio/adc/ad7124.c
> +++ b/drivers/iio/adc/ad7124.c
> @@ -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>
> @@ -301,11 +302,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;
>
Powered by blists - more mailing lists