[PATCH v7] iio: frequency: ad9832: simplify bitwise math
From: Joshua Crofts
Date: Sun Apr 19 2026 - 14:37:18 EST
Refactor the ad9832_calc_freqreg by removing the redundant u64 casts
and 1L bitwise left shift and replacing the multiplication by a bit
shift, as multiplying integers by a power of two is identical to a
bitwise left shift.
Signed-off-by: Joshua Crofts <joshua.crofts1@xxxxxxxxx>
Reviewed-by: Nuno Sá <nuno.sa@xxxxxxxxxx>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@xxxxxxxxx>
---
v7:
- replaced multiplication with bitwise left shift
drivers/staging/iio/frequency/ad9832.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/staging/iio/frequency/ad9832.c b/drivers/staging/iio/frequency/ad9832.c
index c0b7852f1c..659821a1e2 100644
--- a/drivers/staging/iio/frequency/ad9832.c
+++ b/drivers/staging/iio/frequency/ad9832.c
@@ -117,8 +117,8 @@ struct ad9832_state {
static unsigned long ad9832_calc_freqreg(unsigned long mclk, unsigned long fout)
{
- unsigned long long freqreg = (u64)fout *
- (u64)((u64)1L << AD9832_FREQ_BITS);
+ u64 freqreg = (u64)fout << AD9832_FREQ_BITS;
+
do_div(freqreg, mclk);
return freqreg;
}
--
2.34.1