Re: [PATCH v6 2/2] iio: frequency: ad9832: simplify bitwise math
From: Jonathan Cameron
Date: Sun Apr 19 2026 - 12:52:25 EST
On Fri, 17 Apr 2026 10:16:23 +0000
Joshua Crofts <joshua.crofts1@xxxxxxxxx> wrote:
> Refactor the ad9832_calc_freqreg by adding a BIT_ULL() macro instead of
> manual bit shifting for better readability.
>
> Signed-off-by: Joshua Crofts <joshua.crofts1@xxxxxxxxx>
> Reviewed-by: Nuno Sá <nuno.sa@xxxxxxxxxx>
> Reviewed-by: Andy Shevchenko <andriy.shevchenko@xxxxxxxxx>
> ---
> 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..6ce9651542 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 * BIT_ULL(AD9832_FREQ_BITS);
https://sashiko.dev/#/patchset/20260417101623.1281-1-joshua.crofts1%40gmail.com
So does this actually improve readability? Sashiko had fun with this one and
I'm somewhat inclined to agree with it. The suggestion it made was that
the following was more readable still and avoided oddity of using BIT_ULL as
a multiplier.
u64 freqreg = (u64)fout << AD9832_FREQ_BITS;
> +
> do_div(freqreg, mclk);
> return freqreg;
> }