Re: [PATCH 2/2] iio: frequency: ad9832: simplify bitwise math

From: David Lechner

Date: Fri Apr 10 2026 - 15:17:39 EST


On 4/10/26 5:08 AM, Joshua Crofts 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>
> ---
> drivers/staging/iio/frequency/ad9832.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/drivers/staging/iio/frequency/ad9832.c b/drivers/staging/iio/frequency/ad9832.c
> index 1f6ece79b8..260c2e3a9b 100644
> --- a/drivers/staging/iio/frequency/ad9832.c
> +++ b/drivers/staging/iio/frequency/ad9832.c
> @@ -113,8 +113,7 @@ 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);
> + unsigned long long freqreg = (u64)fout * BIT_ULL(AD9832_FREQ_BITS);

If we are touching this line anyway, I would change `unsigned long long`
to `u64` to make the type name consistent with the cast and makes the
line shorter.

> do_div(freqreg, mclk);
> return freqreg;
> }