* [PATCH] iio: adc: ad7625: fix type mismatch in clamp() macro
@ 2026-04-22 14:25 Giorgi Tchankvetadze
2026-04-22 16:20 ` Andy Shevchenko
0 siblings, 1 reply; 3+ messages in thread
From: Giorgi Tchankvetadze @ 2026-04-22 14:25 UTC (permalink / raw)
To: antoniu.miclaus, lars, Michael.Hennerich, jic23
Cc: dlechner, nuno.sa, andy, linux-iio, linux-kernel,
Giorgi Tchankvetadze
Smatch reports a type mismatch warning in ad7625_set_sampling_freq()
where the clamp() macro is evaluating differing types:
- `target` is a u32
- `100` evaluates as a signed int
- `10 * KILO` evaluates as an unsigned long (due to KILO being 1000UL)
Replace clamp() with clamp_t(u32, ...) to explicitly cast the bounds
to match the u32 target variable.
Signed-off-by: Giorgi Tchankvetadze <giorgitchankvetadze1997@gmail.com>
---
drivers/iio/adc/ad7625.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/iio/adc/ad7625.c b/drivers/iio/adc/ad7625.c
index 0466c0c7eae4..fb0fe2434c68 100644
--- a/drivers/iio/adc/ad7625.c
+++ b/drivers/iio/adc/ad7625.c
@@ -180,7 +180,7 @@ static int ad7625_set_sampling_freq(struct ad7625_state *st, u32 freq)
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_t(u32, target, 100, 10 * KILO);
/*
* Use the maximum conversion time t_CNVH from the datasheet as
--
2.52.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] iio: adc: ad7625: fix type mismatch in clamp() macro
2026-04-22 14:25 [PATCH] iio: adc: ad7625: fix type mismatch in clamp() macro Giorgi Tchankvetadze
@ 2026-04-22 16:20 ` Andy Shevchenko
2026-04-22 16:21 ` Andy Shevchenko
0 siblings, 1 reply; 3+ messages in thread
From: Andy Shevchenko @ 2026-04-22 16:20 UTC (permalink / raw)
To: Giorgi Tchankvetadze
Cc: antoniu.miclaus, lars, Michael.Hennerich, jic23, dlechner,
nuno.sa, andy, linux-iio, linux-kernel
On Wed, Apr 22, 2026 at 06:25:42PM +0400, Giorgi Tchankvetadze wrote:
> Smatch reports a type mismatch warning in ad7625_set_sampling_freq()
> where the clamp() macro is evaluating differing types:
> - `target` is a u32
> - `100` evaluates as a signed int
> - `10 * KILO` evaluates as an unsigned long (due to KILO being 1000UL)
> Replace clamp() with clamp_t(u32, ...) to explicitly cast the bounds
> to match the u32 target variable.
No. Try to avoid as much as possible use of _t variants of max(), clamp(),
and min() (the list is sorted from the least critical to the most),
Also we have constant multipliers for frequency in units.h.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] iio: adc: ad7625: fix type mismatch in clamp() macro
2026-04-22 16:20 ` Andy Shevchenko
@ 2026-04-22 16:21 ` Andy Shevchenko
0 siblings, 0 replies; 3+ messages in thread
From: Andy Shevchenko @ 2026-04-22 16:21 UTC (permalink / raw)
To: Giorgi Tchankvetadze
Cc: antoniu.miclaus, lars, Michael.Hennerich, jic23, dlechner,
nuno.sa, andy, linux-iio, linux-kernel
On Wed, Apr 22, 2026 at 07:20:06PM +0300, Andy Shevchenko wrote:
> On Wed, Apr 22, 2026 at 06:25:42PM +0400, Giorgi Tchankvetadze wrote:
> > Smatch reports a type mismatch warning in ad7625_set_sampling_freq()
> > where the clamp() macro is evaluating differing types:
> > - `target` is a u32
> > - `100` evaluates as a signed int
> > - `10 * KILO` evaluates as an unsigned long (due to KILO being 1000UL)
>
> > Replace clamp() with clamp_t(u32, ...) to explicitly cast the bounds
> > to match the u32 target variable.
>
> No. Try to avoid as much as possible use of _t variants of max(), clamp(),
> and min() (the list is sorted from the least critical to the most),
>
> Also we have constant multipliers for frequency in units.h.
Reading again it seems like one from time.h actually fits better NSEC_PER_USEC.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-04-22 16:21 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-22 14:25 [PATCH] iio: adc: ad7625: fix type mismatch in clamp() macro Giorgi Tchankvetadze
2026-04-22 16:20 ` Andy Shevchenko
2026-04-22 16:21 ` Andy Shevchenko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox