public inbox for linux-staging@lists.linux.dev
 help / color / mirror / Atom feed
* [PATCH] staging: iio: ad5933: Use div64_ul instead of do_div
@ 2022-10-27 21:28 Deepak R Varma
  2022-10-28 10:11 ` Sa, Nuno
  2022-10-29  7:52 ` Greg Kroah-Hartman
  0 siblings, 2 replies; 6+ messages in thread
From: Deepak R Varma @ 2022-10-27 21:28 UTC (permalink / raw)
  To: outreachy, Lars-Peter Clausen, Michael Hennerich,
	Jonathan Cameron, Greg Kroah-Hartman, linux-iio, linux-staging,
	linux-kernel

do_div() does a 64-by-32 division. Here the divisor is an unsigned long
which on some platforms is 64 bit wide. So use div64_ul instead of do_div
to avoid a possible truncation. Issue was identified using the
coccicheck tool.

Signed-off-by: Deepak R Varma <drv@mailo.com>
---
 drivers/staging/iio/impedance-analyzer/ad5933.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/iio/impedance-analyzer/ad5933.c b/drivers/staging/iio/impedance-analyzer/ad5933.c
index f177b20f0f2d..730bb31a20d8 100644
--- a/drivers/staging/iio/impedance-analyzer/ad5933.c
+++ b/drivers/staging/iio/impedance-analyzer/ad5933.c
@@ -196,7 +196,7 @@ static int ad5933_set_freq(struct ad5933_state *st,
 	} dat;

 	freqreg = (u64)freq * (u64)(1 << 27);
-	do_div(freqreg, st->mclk_hz / 4);
+	freqreg = div64_ul(freqreg, st->mclk_hz / 4);

 	switch (reg) {
 	case AD5933_REG_FREQ_START:
--
2.34.1




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

end of thread, other threads:[~2022-11-04 18:47 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-10-27 21:28 [PATCH] staging: iio: ad5933: Use div64_ul instead of do_div Deepak R Varma
2022-10-28 10:11 ` Sa, Nuno
2022-10-29 11:23   ` David Laight
2022-11-04 18:47     ` Deepak R Varma
2022-10-29  7:52 ` Greg Kroah-Hartman
2022-10-31 10:06   ` Deepak R Varma

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