public inbox for linux-staging@lists.linux.dev
 help / color / mirror / Atom feed
* [PATCH v2] staging: iio: impedance-analyzer: ad5933: use div64_ul() instead of do_div()
@ 2026-02-18 12:53 Archit Anant
  2026-02-18 13:51 ` Andy Shevchenko
  0 siblings, 1 reply; 6+ messages in thread
From: Archit Anant @ 2026-02-18 12:53 UTC (permalink / raw)
  To: jic23, lars, Michael.Hennerich
  Cc: gregkh, dlechner, nuno.sa, andy, linux-iio, linux-staging,
	linux-kernel, Archit Anant

Replace do_div() with div64_ul() since the remainder is not used.
div64_ul() is the preferred API for 64-bit by 32-bit division when
only the quotient is needed.

Also replace explicit casting and shifting with the BIT_ULL(27) macro
for clarity.

Note: A mathematical simplification to `(freq * BIT_ULL(29)) / mclk` was
suggested during review to improve precision. However, as confirmed by
maintainers, the original driver's truncation via `(mclk / 4)` might
be intentional or relied upon by userspace. Since hardware is not
available for verification, this patch preserves the original logic
to avoid regression risk in the absence of testing.

Issue identified by coccicheck using do_div.cocci.

Changes in v2:
- Replaced explicit `(u64)(1 << 27)` with `BIT_ULL(27)` as suggested by Andy Shevchenko.
- Kept original arithmetic logic `(mclk / 4)` to preserve behavior.

Signed-off-by: Archit Anant <architanant5@gmail.com>
---
 drivers/staging/iio/impedance-analyzer/ad5933.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/iio/impedance-analyzer/ad5933.c b/drivers/staging/iio/impedance-analyzer/ad5933.c
index 85a4223295cd..f6d3d98b6c6a 100644
--- a/drivers/staging/iio/impedance-analyzer/ad5933.c
+++ b/drivers/staging/iio/impedance-analyzer/ad5933.c
@@ -5,6 +5,7 @@
  * Copyright 2011 Analog Devices Inc.
  */
 
+#include <linux/bits.h>
 #include <linux/clk.h>
 #include <linux/delay.h>
 #include <linux/device.h>
@@ -194,8 +195,7 @@ static int ad5933_set_freq(struct ad5933_state *st,
 		u8 d8[4];
 	} dat;
 
-	freqreg = (u64)freq * (u64)(1 << 27);
-	do_div(freqreg, st->mclk_hz / 4);
+	freqreg = div64_ul(BIT_ULL(27) * freq, st->mclk_hz / 4);
 
 	switch (reg) {
 	case AD5933_REG_FREQ_START:
-- 
2.39.5


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] staging: iio: impedance-analyzer: ad5933: use div64_ul() instead of do_div()
  2026-02-18 12:53 [PATCH v2] staging: iio: impedance-analyzer: ad5933: use div64_ul() instead of do_div() Archit Anant
@ 2026-02-18 13:51 ` Andy Shevchenko
  2026-02-22 13:43   ` Jonathan Cameron
  0 siblings, 1 reply; 6+ messages in thread
From: Andy Shevchenko @ 2026-02-18 13:51 UTC (permalink / raw)
  To: Archit Anant
  Cc: jic23, lars, Michael.Hennerich, gregkh, dlechner, nuno.sa, andy,
	linux-iio, linux-staging, linux-kernel

On Wed, Feb 18, 2026 at 06:23:27PM +0530, Archit Anant wrote:
> Replace do_div() with div64_ul() since the remainder is not used.
> div64_ul() is the preferred API for 64-bit by 32-bit division when
> only the quotient is needed.
> 
> Also replace explicit casting and shifting with the BIT_ULL(27) macro
> for clarity.
> 
> Note: A mathematical simplification to `(freq * BIT_ULL(29)) / mclk` was
> suggested during review to improve precision. However, as confirmed by
> maintainers, the original driver's truncation via `(mclk / 4)` might
> be intentional or relied upon by userspace. Since hardware is not
> available for verification, this patch preserves the original logic
> to avoid regression risk in the absence of testing.
> 
> Issue identified by coccicheck using do_div.cocci.

> Changes in v2:
> - Replaced explicit `(u64)(1 << 27)` with `BIT_ULL(27)` as suggested by Andy Shevchenko.
> - Kept original arithmetic logic `(mclk / 4)` to preserve behavior.

The place for changelog (and comments)...

> Signed-off-by: Archit Anant <architanant5@gmail.com>
> ---

...is here.

But do not resend until maintainers explicitly ask for that.

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] staging: iio: impedance-analyzer: ad5933: use div64_ul() instead of do_div()
  2026-02-18 13:51 ` Andy Shevchenko
@ 2026-02-22 13:43   ` Jonathan Cameron
  2026-02-23  8:37     ` Andy Shevchenko
  0 siblings, 1 reply; 6+ messages in thread
From: Jonathan Cameron @ 2026-02-22 13:43 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Archit Anant, lars, Michael.Hennerich, gregkh, dlechner, nuno.sa,
	andy, linux-iio, linux-staging, linux-kernel

On Wed, 18 Feb 2026 15:51:14 +0200
Andy Shevchenko <andriy.shevchenko@intel.com> wrote:

> On Wed, Feb 18, 2026 at 06:23:27PM +0530, Archit Anant wrote:
> > Replace do_div() with div64_ul() since the remainder is not used.
> > div64_ul() is the preferred API for 64-bit by 32-bit division when
> > only the quotient is needed.
> > 
> > Also replace explicit casting and shifting with the BIT_ULL(27) macro
> > for clarity.
> > 
> > Note: A mathematical simplification to `(freq * BIT_ULL(29)) / mclk` was
> > suggested during review to improve precision. However, as confirmed by
> > maintainers, the original driver's truncation via `(mclk / 4)` might
> > be intentional or relied upon by userspace. Since hardware is not
> > available for verification, this patch preserves the original logic
> > to avoid regression risk in the absence of testing.
> > 
> > Issue identified by coccicheck using do_div.cocci.  
> 
> > Changes in v2:
> > - Replaced explicit `(u64)(1 << 27)` with `BIT_ULL(27)` as suggested by Andy Shevchenko.
> > - Kept original arithmetic logic `(mclk / 4)` to preserve behavior.  
> 
> The place for changelog (and comments)...
> 
> > Signed-off-by: Archit Anant <architanant5@gmail.com>
> > ---  
> 
> ...is here.
> 
> But do not resend until maintainers explicitly ask for that.
> 
Tweaked commit message as Andy pointed out was needed.

Applied to the togreg branch of iio.git

Andy, if you want to give a tag I can role that in for now as need
to rebase anyway on rc1.  This mail felt like an 'almost tag' ;)

Thanks,

Jonathan



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] staging: iio: impedance-analyzer: ad5933: use div64_ul() instead of do_div()
  2026-02-22 13:43   ` Jonathan Cameron
@ 2026-02-23  8:37     ` Andy Shevchenko
  2026-02-23 20:44       ` Jonathan Cameron
  0 siblings, 1 reply; 6+ messages in thread
From: Andy Shevchenko @ 2026-02-23  8:37 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Archit Anant, lars, Michael.Hennerich, gregkh, dlechner, nuno.sa,
	andy, linux-iio, linux-staging, linux-kernel

On Sun, Feb 22, 2026 at 01:43:26PM +0000, Jonathan Cameron wrote:
> On Wed, 18 Feb 2026 15:51:14 +0200
> Andy Shevchenko <andriy.shevchenko@intel.com> wrote:
> > On Wed, Feb 18, 2026 at 06:23:27PM +0530, Archit Anant wrote:
> > > Replace do_div() with div64_ul() since the remainder is not used.
> > > div64_ul() is the preferred API for 64-bit by 32-bit division when
> > > only the quotient is needed.
> > > 
> > > Also replace explicit casting and shifting with the BIT_ULL(27) macro
> > > for clarity.
> > > 
> > > Note: A mathematical simplification to `(freq * BIT_ULL(29)) / mclk` was
> > > suggested during review to improve precision. However, as confirmed by
> > > maintainers, the original driver's truncation via `(mclk / 4)` might
> > > be intentional or relied upon by userspace. Since hardware is not
> > > available for verification, this patch preserves the original logic
> > > to avoid regression risk in the absence of testing.
> > > 
> > > Issue identified by coccicheck using do_div.cocci.  
> > 
> > > Changes in v2:
> > > - Replaced explicit `(u64)(1 << 27)` with `BIT_ULL(27)` as suggested by Andy Shevchenko.
> > > - Kept original arithmetic logic `(mclk / 4)` to preserve behavior.  
> > 
> > The place for changelog (and comments)...
> > 
> > > Signed-off-by: Archit Anant <architanant5@gmail.com>
> > > ---  
> > 
> > ...is here.
> > 
> > But do not resend until maintainers explicitly ask for that.
> > 
> Tweaked commit message as Andy pointed out was needed.
> 
> Applied to the togreg branch of iio.git
> 
> Andy, if you want to give a tag I can role that in for now as need
> to rebase anyway on rc1.  This mail felt like an 'almost tag' ;)

I think you are talking about my Rb? Sure
Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] staging: iio: impedance-analyzer: ad5933: use div64_ul() instead of do_div()
  2026-02-23  8:37     ` Andy Shevchenko
@ 2026-02-23 20:44       ` Jonathan Cameron
  2026-02-24  3:41         ` Archit Anant
  0 siblings, 1 reply; 6+ messages in thread
From: Jonathan Cameron @ 2026-02-23 20:44 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Archit Anant, lars, Michael.Hennerich, gregkh, dlechner, nuno.sa,
	andy, linux-iio, linux-staging, linux-kernel

On Mon, 23 Feb 2026 10:37:11 +0200
Andy Shevchenko <andriy.shevchenko@intel.com> wrote:

> On Sun, Feb 22, 2026 at 01:43:26PM +0000, Jonathan Cameron wrote:
> > On Wed, 18 Feb 2026 15:51:14 +0200
> > Andy Shevchenko <andriy.shevchenko@intel.com> wrote:  
> > > On Wed, Feb 18, 2026 at 06:23:27PM +0530, Archit Anant wrote:  
> > > > Replace do_div() with div64_ul() since the remainder is not used.
> > > > div64_ul() is the preferred API for 64-bit by 32-bit division when
> > > > only the quotient is needed.
> > > > 
> > > > Also replace explicit casting and shifting with the BIT_ULL(27) macro
> > > > for clarity.
> > > > 
> > > > Note: A mathematical simplification to `(freq * BIT_ULL(29)) / mclk` was
> > > > suggested during review to improve precision. However, as confirmed by
> > > > maintainers, the original driver's truncation via `(mclk / 4)` might
> > > > be intentional or relied upon by userspace. Since hardware is not
> > > > available for verification, this patch preserves the original logic
> > > > to avoid regression risk in the absence of testing.
> > > > 
> > > > Issue identified by coccicheck using do_div.cocci.    
> > >   
> > > > Changes in v2:
> > > > - Replaced explicit `(u64)(1 << 27)` with `BIT_ULL(27)` as suggested by Andy Shevchenko.
> > > > - Kept original arithmetic logic `(mclk / 4)` to preserve behavior.    
> > > 
> > > The place for changelog (and comments)...
> > >   
> > > > Signed-off-by: Archit Anant <architanant5@gmail.com>
> > > > ---    
> > > 
> > > ...is here.
> > > 
> > > But do not resend until maintainers explicitly ask for that.
> > >   
> > Tweaked commit message as Andy pointed out was needed.
> > 
> > Applied to the togreg branch of iio.git
> > 
> > Andy, if you want to give a tag I can role that in for now as need
> > to rebase anyway on rc1.  This mail felt like an 'almost tag' ;)  
> 
> I think you are talking about my Rb? Sure
> Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
> 
Added. Thanks,


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] staging: iio: impedance-analyzer: ad5933: use div64_ul() instead of do_div()
  2026-02-23 20:44       ` Jonathan Cameron
@ 2026-02-24  3:41         ` Archit Anant
  0 siblings, 0 replies; 6+ messages in thread
From: Archit Anant @ 2026-02-24  3:41 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Andy Shevchenko, lars, Michael.Hennerich, gregkh, dlechner,
	nuno.sa, andy, linux-iio, linux-staging, linux-kernel

On Tue, Feb 24, 2026 at 2:14 AM Jonathan Cameron <jic23@kernel.org> wrote:
>
...
> > > Tweaked commit message as Andy pointed out was needed.
> > >
> > > Applied to the togreg branch of iio.git
> > >
> > > Andy, if you want to give a tag I can role that in for now as need
> > > to rebase anyway on rc1.  This mail felt like an 'almost tag' ;)
> >
> > I think you are talking about my Rb? Sure
> > Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
> >
> Added. Thanks,
>
Hi Jonathan, Andy,

Thank you Jonathan for the help with the commit message and thank you
Andy for the math optimization guidance.

I've learned a lot from this discussion.

-- 
Sincerely,
Archit Anant

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-02-24  3:41 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-18 12:53 [PATCH v2] staging: iio: impedance-analyzer: ad5933: use div64_ul() instead of do_div() Archit Anant
2026-02-18 13:51 ` Andy Shevchenko
2026-02-22 13:43   ` Jonathan Cameron
2026-02-23  8:37     ` Andy Shevchenko
2026-02-23 20:44       ` Jonathan Cameron
2026-02-24  3:41         ` Archit Anant

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox