From: David Laight <david.laight.linux@gmail.com>
To: Giorgi Tchankvetadze <giorgitchankvetadze1997@gmail.com>
Cc: antoniu.miclaus@analog.com, lars@metafoo.de,
Michael.Hennerich@analog.com, jic23@kernel.org,
dlechner@baylibre.com, nuno.sa@analog.com, andy@kernel.org,
linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Subject: Re: [PATCH v2] iio: adc: ad7625: fix type mismatch in clamp() macro
Date: Mon, 27 Apr 2026 14:28:06 +0100 [thread overview]
Message-ID: <20260427142806.58140ed6@pumpkin> (raw)
In-Reply-To: <20260425071615.20406-2-giorgitchankvetadze1997@gmail.com>
On Sat, 25 Apr 2026 11:16:16 +0400
Giorgi Tchankvetadze <giorgitchankvetadze1997@gmail.com> wrote:
> clamp() expects compatible operand types. The period calculation uses
> nanosecond constants, while the local target variable was narrower than
> the upper bound expression.
All the variables and values look to be valid for unsigned comparisons.
So what are you trying to fix?
>
> Make target unsigned long and use unsigned long bounds, including
> NSEC_PER_USEC for the upper limit. This keeps the operands naturally
> aligned without adding casts.
Changing 'u32' to 'unsigned long' shouldn't make any difference.
The code (probably) has to run on 32bit cpu where both are 32bits.
The upper limit is on 10000 (regardless of how you define it)
so it always fits in u32 (or even u16 - but don't go there).
Indeed NSEC_PER_SEC is less than INT_MAX, so dividing it by anything
gives a value that fits in u32.
So exactly what are you trying to fix?
David
>
> Suggested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> Signed-off-by: Giorgi Tchankvetadze <giorgitchankvetadze1997@gmail.com>
> ---
> Changes in v2:
> - Make target unsigned long and use unsigned long clamp bounds.
> - Use NSEC_PER_USEC for the upper bound.
> - Avoid casts, as suggested by Andy.
>
> drivers/iio/adc/ad7625.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/iio/adc/ad7625.c b/drivers/iio/adc/ad7625.c
> index 0466c0c7eae4..b5a7911c75df 100644
> --- a/drivers/iio/adc/ad7625.c
> +++ b/drivers/iio/adc/ad7625.c
> @@ -175,12 +175,12 @@ enum ad7960_mode {
>
> static int ad7625_set_sampling_freq(struct ad7625_state *st, u32 freq)
> {
> - u32 target;
> + unsigned long target;
> struct pwm_waveform clk_gate_wf = { }, cnv_wf = { };
> int ret;
>
> target = DIV_ROUND_UP(NSEC_PER_SEC, freq);
> - cnv_wf.period_length_ns = clamp(target, 100, 10 * KILO);
> + cnv_wf.period_length_ns = clamp(target, 100UL, 10UL * NSEC_PER_USEC);
>
> /*
> * Use the maximum conversion time t_CNVH from the datasheet as
prev parent reply other threads:[~2026-04-27 13:28 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20260425071615.20406-2-giorgitchankvetadze1997@gmail.com>
2026-04-27 7:31 ` [PATCH v2] iio: adc: ad7625: fix type mismatch in clamp() macro Andy Shevchenko
2026-04-27 9:52 ` Jonathan Cameron
2026-04-27 13:28 ` David Laight [this message]
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=20260427142806.58140ed6@pumpkin \
--to=david.laight.linux@gmail.com \
--cc=Michael.Hennerich@analog.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=andy@kernel.org \
--cc=antoniu.miclaus@analog.com \
--cc=dlechner@baylibre.com \
--cc=giorgitchankvetadze1997@gmail.com \
--cc=jic23@kernel.org \
--cc=lars@metafoo.de \
--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