drivers/staging/iio/frequency/ad9832.c | 7 +++++++ drivers/staging/iio/frequency/ad9834.c | 7 +++++++ 2 files changed, 14 insertions(+)
Previous attempts to change do_div() to div64_ul() were rejected because
mclk will always fit within 32 bits for this hardware, making do_div()
safe to use.
However, Coccinelle continues to flag this as a false positive. To
prevent future developers from submitting unnecessary fixes, add a
comment explaining why do_div() is intentionally kept.
Suggested-by: Andy Shevchenko <andriy.shevchenko@intel.com>
Signed-off-by: Mohamad Raizudeen <raizudeen.kerneldev@gmail.com>
---
Changes in v2:
- Instead of changing do_div to div64_ul, added a comment explaining why
do_div is kept, as requested by Andy Shevchenko and Joshua Crofts.
drivers/staging/iio/frequency/ad9832.c | 7 +++++++
drivers/staging/iio/frequency/ad9834.c | 7 +++++++
2 files changed, 14 insertions(+)
diff --git a/drivers/staging/iio/frequency/ad9832.c b/drivers/staging/iio/frequency/ad9832.c
index 60c33e10c46f..6d046e9121e2 100644
--- a/drivers/staging/iio/frequency/ad9832.c
+++ b/drivers/staging/iio/frequency/ad9832.c
@@ -118,6 +118,13 @@ static unsigned long ad9832_calc_freqreg(unsigned long mclk, unsigned long fout)
{
u64 freqreg = (u64)fout << AD9832_FREQ_BITS;
+ /*
+ * mclk is an unsigned long, which triggers a Coccinelle false positive
+ * warning about using do_div() for 64-by-32 division. However, mclk
+ * for this hardware will always fit within 32 bits, so do_div() is
+ * safe to use here.
+ */
+
do_div(freqreg, mclk);
return freqreg;
}
diff --git a/drivers/staging/iio/frequency/ad9834.c b/drivers/staging/iio/frequency/ad9834.c
index 33dfd723923c..8722f3a01cde 100644
--- a/drivers/staging/iio/frequency/ad9834.c
+++ b/drivers/staging/iio/frequency/ad9834.c
@@ -103,6 +103,13 @@ static unsigned int ad9834_calc_freqreg(unsigned long mclk, unsigned long fout)
{
unsigned long long freqreg = (u64)fout * (u64)BIT(AD9834_FREQ_BITS);
+ /*
+ * mclk is an unsigned long, which triggers a Coccinelle false positive
+ * warning about using do_div() for 64-by-32 division. However, mclk
+ * for this hardware will always fit within 32 bits, so do_div() is
+ * safe to use here.
+ */
+
do_div(freqreg, mclk);
return freqreg;
}
--
2.53.0
On Wed, 22 Jul 2026 13:52:27 +0530
Mohamad Raizudeen <raizudeen.kerneldev@gmail.com> wrote:
> Previous attempts to change do_div() to div64_ul() were rejected because
> mclk will always fit within 32 bits for this hardware, making do_div()
> safe to use.
>
> However, Coccinelle continues to flag this as a false positive. To
> prevent future developers from submitting unnecessary fixes, add a
> comment explaining why do_div() is intentionally kept.
>
> Suggested-by: Andy Shevchenko <andriy.shevchenko@intel.com>
> Signed-off-by: Mohamad Raizudeen <raizudeen.kerneldev@gmail.com>
> ---
Please don't send a new version as a reply to the previous version,
as it can break tooling such as b4 for patch review.
As for the comment, I think it's good, however I'm not sure whether
this should be split into two patches, given that this is a small
change. Andy, what do you think?
> diff --git a/drivers/staging/iio/frequency/ad9832.c b/drivers/staging/iio/frequency/ad9832.c
> index 60c33e10c46f..6d046e9121e2 100644
> --- a/drivers/staging/iio/frequency/ad9832.c
> +++ b/drivers/staging/iio/frequency/ad9832.c
> @@ -118,6 +118,13 @@ static unsigned long ad9832_calc_freqreg(unsigned long mclk, unsigned long fout)
> {
> u64 freqreg = (u64)fout << AD9832_FREQ_BITS;
>
> + /*
> + * mclk is an unsigned long, which triggers a Coccinelle false positive
> + * warning about using do_div() for 64-by-32 division. However, mclk
> + * for this hardware will always fit within 32 bits, so do_div() is
> + * safe to use here.
> + */
> +
Unnecessary blank line here, you want to couple the comment with the
line that it's describing.
> do_div(freqreg, mclk);
> return freqreg;
> }
> diff --git a/drivers/staging/iio/frequency/ad9834.c b/drivers/staging/iio/frequency/ad9834.c
> index 33dfd723923c..8722f3a01cde 100644
> --- a/drivers/staging/iio/frequency/ad9834.c
> +++ b/drivers/staging/iio/frequency/ad9834.c
> @@ -103,6 +103,13 @@ static unsigned int ad9834_calc_freqreg(unsigned long mclk, unsigned long fout)
> {
> unsigned long long freqreg = (u64)fout * (u64)BIT(AD9834_FREQ_BITS);
>
> + /*
> + * mclk is an unsigned long, which triggers a Coccinelle false positive
> + * warning about using do_div() for 64-by-32 division. However, mclk
> + * for this hardware will always fit within 32 bits, so do_div() is
> + * safe to use here.
> + */
> +
Ditto.
> do_div(freqreg, mclk);
> return freqreg;
> }
--
Kind regards,
Joshua Crofts
On Wed, Jul 22, 2026 at 10:46:17AM +0200, Joshua Crofts wrote:
> On Wed, 22 Jul 2026 13:52:27 +0530
> Mohamad Raizudeen <raizudeen.kerneldev@gmail.com> wrote:
> > Previous attempts to change do_div() to div64_ul() were rejected because
> > mclk will always fit within 32 bits for this hardware, making do_div()
> > safe to use.
> >
> > However, Coccinelle continues to flag this as a false positive. To
> > prevent future developers from submitting unnecessary fixes, add a
> > comment explaining why do_div() is intentionally kept.
> >
> > Suggested-by: Andy Shevchenko <andriy.shevchenko@intel.com>
> > Signed-off-by: Mohamad Raizudeen <raizudeen.kerneldev@gmail.com>
> > ---
>
> Please don't send a new version as a reply to the previous version,
> as it can break tooling such as b4 for patch review.
>
> As for the comment, I think it's good, however I'm not sure whether
> this should be split into two patches, given that this is a small
> change. Andy, what do you think?
>
> > diff --git a/drivers/staging/iio/frequency/ad9832.c b/drivers/staging/iio/frequency/ad9832.c
> > index 60c33e10c46f..6d046e9121e2 100644
> > --- a/drivers/staging/iio/frequency/ad9832.c
> > +++ b/drivers/staging/iio/frequency/ad9832.c
> > @@ -118,6 +118,13 @@ static unsigned long ad9832_calc_freqreg(unsigned long mclk, unsigned long fout)
> > {
> > u64 freqreg = (u64)fout << AD9832_FREQ_BITS;
> >
> > + /*
> > + * mclk is an unsigned long, which triggers a Coccinelle false positive
> > + * warning about using do_div() for 64-by-32 division. However, mclk
> > + * for this hardware will always fit within 32 bits, so do_div() is
> > + * safe to use here.
> > + */
> > +
>
> Unnecessary blank line here, you want to couple the comment with the
> line that it's describing.
>
> > do_div(freqreg, mclk);
> > return freqreg;
> > }
> > diff --git a/drivers/staging/iio/frequency/ad9834.c b/drivers/staging/iio/frequency/ad9834.c
> > index 33dfd723923c..8722f3a01cde 100644
> > --- a/drivers/staging/iio/frequency/ad9834.c
> > +++ b/drivers/staging/iio/frequency/ad9834.c
> > @@ -103,6 +103,13 @@ static unsigned int ad9834_calc_freqreg(unsigned long mclk, unsigned long fout)
> > {
> > unsigned long long freqreg = (u64)fout * (u64)BIT(AD9834_FREQ_BITS);
> >
> > + /*
> > + * mclk is an unsigned long, which triggers a Coccinelle false positive
> > + * warning about using do_div() for 64-by-32 division. However, mclk
> > + * for this hardware will always fit within 32 bits, so do_div() is
> > + * safe to use here.
> > + */
> > +
>
> Ditto.
>
> > do_div(freqreg, mclk);
> > return freqreg;
> > }
>
>
>
> --
> Kind regards,
> Joshua Crofts
Hi Joshua,
Thanks you for reviewing the patch and for the clarifications.
I understood and will make sure v3 is sent as a new and separate email
thread without in-reply-to header so i doesn't break b4.
Sure, I will remove the unnecessary blank line.
I will hold off sending v3 until I hear from Andy regarding whether this should be split
into two patches or kept as one.
Thanks & regards,
Mohamad Raizudeen
© 2016 - 2026 Red Hat, Inc.