[PATCH v4] staging: iio: frequency: ad9832/ad9834: add comment explaining do_div usage

Mohamad Raizudeen posted 1 patch 1 month, 3 weeks ago
drivers/staging/iio/frequency/ad9832.c | 6 ++++++
drivers/staging/iio/frequency/ad9834.c | 6 ++++++
2 files changed, 12 insertions(+)
[PATCH v4] staging: iio: frequency: ad9832/ad9834: add comment explaining do_div usage
Posted by Mohamad Raizudeen 1 month, 3 weeks ago
Previous attempts to change do_div() to div64_ul were rejected because
mclk will always fit within 32 fits 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 v4:
- Fixed typo in comment (fir -> fit) as pointed out by Joshua Crofts.

 drivers/staging/iio/frequency/ad9832.c | 6 ++++++
 drivers/staging/iio/frequency/ad9834.c | 6 ++++++
 2 files changed, 12 insertions(+)

diff --git a/drivers/staging/iio/frequency/ad9832.c b/drivers/staging/iio/frequency/ad9832.c
index 60c33e10c46f..2e216c950c53 100644
--- a/drivers/staging/iio/frequency/ad9832.c
+++ b/drivers/staging/iio/frequency/ad9832.c
@@ -118,6 +118,12 @@ 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..e089a94db97d 100644
--- a/drivers/staging/iio/frequency/ad9834.c
+++ b/drivers/staging/iio/frequency/ad9834.c
@@ -103,6 +103,12 @@ 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 a 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
Re: [PATCH v4] staging: iio: frequency: ad9832/ad9834: add comment explaining do_div usage
Posted by Andy Shevchenko 1 month, 3 weeks ago
On Fri, Aug 07, 2026 at 03:17:03PM +0530, Mohamad Raizudeen wrote:
> Previous attempts to change do_div() to div64_ul were rejected because
> mclk will always fit within 32 fits 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.

Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>

-- 
With Best Regards,
Andy Shevchenko
Re: [PATCH v4] staging: iio: frequency: ad9832/ad9834: add comment explaining do_div usage
Posted by Jonathan Cameron 1 month, 1 week ago
On Sat, 8 Aug 2026 23:12:37 +0300
Andy Shevchenko <andriy.shevchenko@intel.com> wrote:

> On Fri, Aug 07, 2026 at 03:17:03PM +0530, Mohamad Raizudeen wrote:
> > Previous attempts to change do_div() to div64_ul were rejected because
> > mclk will always fit within 32 fits 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.  
> 
> Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
> 
Applied to the testing branch of iio.git.  That will become
togreg and turn up in linux-next after I rebase on rc1 (in a few
weeks time)

Thanks,

Jonathan
Re: [PATCH v4] staging: iio: frequency: ad9832/ad9834: add comment explaining do_div usage
Posted by Joshua Crofts 1 month, 3 weeks ago
On Fri,  7 Aug 2026 15:17:03 +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 fits 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>
> ---

Fine now.

Reviewed-by: Joshua Crofts <joshua.crofts1@gmail.com>

-- 
Kind regards,
Joshua Crofts