public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] iio: adc: ad7625: fix type mismatch in clamp() macro
@ 2026-04-25  7:16 Giorgi Tchankvetadze
  2026-04-27  7:31 ` Andy Shevchenko
  2026-04-27 13:28 ` David Laight
  0 siblings, 2 replies; 4+ messages in thread
From: Giorgi Tchankvetadze @ 2026-04-25  7:16 UTC (permalink / raw)
  To: antoniu.miclaus, lars, Michael.Hennerich, jic23
  Cc: dlechner, nuno.sa, andy, linux-iio, linux-kernel,
	Giorgi Tchankvetadze, Andy Shevchenko

clamp() expects compatible operand types. The period calculation uses
nanosecond constants, while the local target variable was narrower than
the upper bound expression.

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.

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
-- 
2.52.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-04-27 13:28 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-25  7:16 [PATCH v2] iio: adc: ad7625: fix type mismatch in clamp() macro Giorgi Tchankvetadze
2026-04-27  7:31 ` Andy Shevchenko
2026-04-27  9:52   ` Jonathan Cameron
2026-04-27 13:28 ` David Laight

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox