From: Joshua Crofts <joshua.crofts1@gmail.com>
To: Mohamad Raizudeen <raizudeen.kerneldev@gmail.com>
Cc: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org,
dlechner@baylibre.com, nuno.sa@analog.com, andy@kernel.org,
gregkh@linuxfoundation.org, skhan@linuxfoundation.org,
linux-iio@vger.kernel.org, linux-staging@lists.linux.dev,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] staging: iio: frequency: ad9832/ad9834: use div64_ul instead of do_div
Date: Tue, 30 Jun 2026 09:39:31 +0200 [thread overview]
Message-ID: <20260630093931.00006eca@gmail.com> (raw)
In-Reply-To: <20260630032322.5805-1-raizudeen.kerneldev@gmail.com>
On Tue, 30 Jun 2026 08:53:22 +0530
Mohamad Raizudeen <raizudeen.kerneldev@gmail.com> wrote:
> Coccinelle warns that do_div() should not be used when the divisor is an unsigned long, because do_div() expects a 32-bit divisor.
>
> In this case, the 'mclk' divisor is an 'unsigned long', which can be 64-bit on certain architectures. The correct function to use here is div64_ul().
>
> Because do_div() modifies the dividend in place, while div64_ul() returns the result, the code was updated to directly return the result of div64_ul. This keeps the math exactly the same but fixes the warning and makes the code safer.
Please try to wrap your lines to 72 characters.
>
> Signed-off-by: Mohamad Raizudeen <raizudeen.kerneldev@gmail.com>
> ---
> drivers/staging/iio/frequency/ad9832.c | 3 +--
> drivers/staging/iio/frequency/ad9834.c | 3 +--
> 2 files changed, 2 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/staging/iio/frequency/ad9832.c b/drivers/staging/iio/frequency/ad9832.c
> index b87ea1781b27..91df7ee65bfc 100644
> --- a/drivers/staging/iio/frequency/ad9832.c
> +++ b/drivers/staging/iio/frequency/ad9832.c
> @@ -115,8 +115,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);
> - do_div(freqreg, mclk);
> - return freqreg;
> + return div64_ul(freqreg, mclk);
> }
I've actually sent a patch for this previously, however the
discussion ended with the fact that there really isn't a point in
doing this, since mclk will always be a value that can fit
into a 32-bit unsigned type, therefore truncation isn't possible.
See here:
https://lore.kernel.org/all/20260409182755.499a419c@pumpkin/
--
Kind regards
CJD
next prev parent reply other threads:[~2026-06-30 7:39 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-30 3:23 [PATCH] staging: iio: frequency: ad9832/ad9834: use div64_ul instead of do_div Mohamad Raizudeen
2026-06-30 7:39 ` Joshua Crofts [this message]
2026-06-30 12:02 ` Andy Shevchenko
2026-06-30 13:07 ` Joshua Crofts
2026-06-30 13:27 ` Dan Carpenter
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260630093931.00006eca@gmail.com \
--to=joshua.crofts1@gmail.com \
--cc=Michael.Hennerich@analog.com \
--cc=andy@kernel.org \
--cc=dlechner@baylibre.com \
--cc=gregkh@linuxfoundation.org \
--cc=jic23@kernel.org \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-staging@lists.linux.dev \
--cc=nuno.sa@analog.com \
--cc=raizudeen.kerneldev@gmail.com \
--cc=skhan@linuxfoundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.