public inbox for linux-iio@vger.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: David Lechner <dlechner@baylibre.com>
Cc: "Michael Hennerich" <Michael.Hennerich@analog.com>,
	"Nuno Sá" <nuno.sa@analog.com>,
	"Andy Shevchenko" <andy@kernel.org>,
	linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/6] iio: adc: ad7124: use clamp()
Date: Sun, 7 Sep 2025 11:02:25 +0100	[thread overview]
Message-ID: <20250907110225.01a6341e@jic23-huawei> (raw)
In-Reply-To: <20250905-iio-adc-ad7124-add-filter-support-v1-1-aee3834be6a9@baylibre.com>

On Fri, 05 Sep 2025 13:11:56 -0500
David Lechner <dlechner@baylibre.com> wrote:

> Use clamp() instead of open-coding clamping.
> 
> Signed-off-by: David Lechner <dlechner@baylibre.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;
> 


  reply	other threads:[~2025-09-07 10:02 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-05 18:11 [PATCH 0/6] iio: adc: ad7124: add filter support David Lechner
2025-09-05 18:11 ` [PATCH 1/6] iio: adc: ad7124: use clamp() David Lechner
2025-09-07 10:02   ` Jonathan Cameron [this message]
2025-09-05 18:11 ` [PATCH 2/6] iio: adc: ad7124: use read_avail() for scale_available David Lechner
2025-09-07 10:04   ` Jonathan Cameron
2025-09-05 18:11 ` [PATCH 3/6] iio: adc: ad7124: use guard(mutex) to simplify return paths David Lechner
2025-09-07 10:06   ` Jonathan Cameron
2025-09-10 16:27     ` Jonathan Cameron
2025-09-05 18:11 ` [PATCH 4/6] iio: adc: ad7124: support fractional sampling_frequency David Lechner
2025-09-05 18:12 ` [PATCH 5/6] iio: adc: ad7124: add filter support David Lechner
2025-09-07 10:22   ` Jonathan Cameron
2025-09-10 16:29     ` Jonathan Cameron
2025-09-05 18:12 ` [PATCH 6/6] iio: ABI: document "sinc4+rej60" filter_type David Lechner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250907110225.01a6341e@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=Michael.Hennerich@analog.com \
    --cc=andy@kernel.org \
    --cc=dlechner@baylibre.com \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nuno.sa@analog.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox