]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
staging: iio: impedance-analyzer: ad5933: use div64_ul() instead of do_div()
authorArchit Anant <architanant5@gmail.com>
Wed, 18 Feb 2026 12:53:27 +0000 (18:23 +0530)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Mon, 23 Feb 2026 20:44:19 +0000 (20:44 +0000)
Replace do_div() with div64_ul() since the remainder is not used.
div64_ul() is the preferred API for 64-bit by 32-bit division when
only the quotient is needed.

Also replace explicit casting and shifting with the BIT_ULL(27) macro
for clarity.

Note: A mathematical simplification to `(freq * BIT_ULL(29)) / mclk` was
suggested during review to improve precision. However, as confirmed by
maintainers, the original driver's truncation via `(mclk / 4)` might
be intentional or relied upon by userspace. Since hardware is not
available for verification, this patch preserves the original logic
to avoid regression risk in the absence of testing.

Issue identified by coccicheck using do_div.cocci.

Signed-off-by: Archit Anant <architanant5@gmail.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/staging/iio/impedance-analyzer/ad5933.c

index 85a4223295cd06840b7f6095019b8d06abeb077f..f6d3d98b6c6a9d33a312faf9a8bb3d403e16e351 100644 (file)
@@ -5,6 +5,7 @@
  * Copyright 2011 Analog Devices Inc.
  */
 
+#include <linux/bits.h>
 #include <linux/clk.h>
 #include <linux/delay.h>
 #include <linux/device.h>
@@ -194,8 +195,7 @@ static int ad5933_set_freq(struct ad5933_state *st,
                u8 d8[4];
        } dat;
 
-       freqreg = (u64)freq * (u64)(1 << 27);
-       do_div(freqreg, st->mclk_hz / 4);
+       freqreg = div64_ul(BIT_ULL(27) * freq, st->mclk_hz / 4);
 
        switch (reg) {
        case AD5933_REG_FREQ_START: