Re: [PATCH v2] iio: frequency: ad983x: replace do_div() with div64_ul().
From: David Lechner
Date: Thu Apr 09 2026 - 11:42:31 EST
On 4/9/26 10:01 AM, Joshua Crofts wrote:
> Coccinelle reported the following in both ad983x drivers:
> do_div() does a 64-by-32 division, please consider using
> div64_ul instead.
>
> Fix this by replacing do_div() with div64_ul(), which
> safely handles 64-bit dividends and unsigned long
> divisors across all architectures.
>
> Signed-off-by: Joshua Crofts <joshua.crofts1@xxxxxxxxx>
> ---
> v2:
Please don't send v2 or later revisions in reply to v1. It breaks
some workflows. Start a new thread instead.
> - resent email with corrected addresses
Instead of a v2, you can just add a RESEND prefix to the subject line
in cases like this. But do include an explanation like this when you
do that.
>
> drivers/staging/iio/frequency/ad9832.c | 3 ++-
> drivers/staging/iio/frequency/ad9834.c | 3 ++-
> 2 files changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/staging/iio/frequency/ad9832.c b/drivers/staging/iio/frequency/ad9832.c
> index b87ea1781b..61ee93263a 100644
> --- a/drivers/staging/iio/frequency/ad9832.c
> +++ b/drivers/staging/iio/frequency/ad9832.c
> @@ -13,6 +13,7 @@
> #include <linux/device.h>
> #include <linux/err.h>
> #include <linux/kernel.h>
> +#include <linux/math64.h>
> #include <linux/module.h>
> #include <linux/regulator/consumer.h>
> #include <linux/slab.h>
> @@ -115,7 +116,7 @@ static unsigned long ad9832_calc_freqreg(unsigned long mclk, unsigned long fout)
> {
> unsigned long long freqreg = (u64)fout *
> (u64)((u64)1L << AD9832_FREQ_BITS);
I would expect checkpatch to complain that there is no blank line
between variable declarations and the rest of the code here.
> - do_div(freqreg, mclk);
> + freqreg = div64_ul(freqreg, mclk);
> return freqreg;
We can just return directly now.
return div64_ul(freqreg, mclk);
> }
>
> diff --git a/drivers/staging/iio/frequency/ad9834.c b/drivers/staging/iio/frequency/ad9834.c
> index d339d5e8e0..83d0e1360c 100644
> --- a/drivers/staging/iio/frequency/ad9834.c
> +++ b/drivers/staging/iio/frequency/ad9834.c
> @@ -10,6 +10,7 @@
> #include <linux/workqueue.h>
> #include <linux/device.h>
> #include <linux/kernel.h>
> +#include <linux/math64.h>
> #include <linux/slab.h>
> #include <linux/sysfs.h>
> #include <linux/list.h>
> @@ -101,7 +102,7 @@ static unsigned int ad9834_calc_freqreg(unsigned long mclk, unsigned long fout)
> {
> unsigned long long freqreg = (u64)fout * (u64)BIT(AD9834_FREQ_BITS);
>
> - do_div(freqreg, mclk);
> + freqreg = div64_ul(freqreg, mclk);
> return freqreg;
ditto.
> }
>