staging: iio: impedance-analyzer: ad5933: use div64_ul() instead of do_div()
Subsystems (4)
PATCH v2 1/1 staging: iio: impedance-analyzer: ad5933: use div64_ul() instead of do_div()
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.
--- drivers/staging/iio/impedance-analyzer/ad5933.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/staging/iio/impedance-analyzer/ad5933.c +2 -2
@@ -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 :
Signature · 1 line
2.39.5
Quoted 14 lines · Archit Anant
Replace
do_div()withdiv64_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)) / mclkwas 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.
Quoted 5 lines
Issue identified by coccicheck using
do_div.cocci.Changes in v2:
- Replaced explicit(u64)(1 << 27)withBIT_ULL(27)as suggested by Andy Shevchenko.
- Kept original arithmetic logic(mclk / 4)to preserve behavior.
The place for changelog (and comments)...
Quoted 2 lines
Signed-off-by Archit Anant <[email protected]>---
...is here.
But do not resend until maintainers explicitly ask for that.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 21 lines · On Wed, 18 Feb 2026 15:51:14 +0200 Andy Shevchenko…
Quoted 14 lines · Archit Anant
Replace
do_div()withdiv64_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)) / mclkwas 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.Quoted 5 lines
Issue identified by coccicheck using
do_div.cocci.Changes in v2:
- Replaced explicit(u64)(1 << 27)withBIT_ULL(27)as suggested by Andy Shevchenko.
- Kept original arithmetic logic(mclk / 4)to preserve behavior.
Quoted 9 lines
The place for changelog (and comments)...
Quoted 2 lines
Signed-off-by Archit Anant <[email protected]>---
...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
Andy Shevchenko
Reviewed-byQuoted 30 lines · Jonathan Cameron
Quoted 28 lines · On Wed, 18 Feb 2026 15:51:14 +0200 Andy Shevchenko…
Quoted 14 lines · Archit Anant
Replace
do_div()withdiv64_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)) / mclkwas 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.Quoted 5 lines
Issue identified by coccicheck using
do_div.cocci.Changes in v2:
- Replaced explicit(u64)(1 << 27)withBIT_ULL(27)as suggested by Andy Shevchenko.
- Kept original arithmetic logic(mclk / 4)to preserve behavior.The place for changelog (and comments)...
Quoted 2 lines
Signed-off-by Archit Anant <[email protected]>---
...is here.
Quoted 8 lines
Quoted 2 lines
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
Signature · 2 lines
With Best Regards, Andy Shevchenko
Jonathan Cameron
maintainerQuoted 35 lines · On Mon, 23 Feb 2026 10:37:11 +0200 Andy Shevchenko…
Quoted 34 lines · Jonathan Cameron
Quoted 21 lines · On Wed, 18 Feb 2026 15:51:14 +0200 Andy Shevchenko…
Quoted 14 lines · Archit Anant
Replace
do_div()withdiv64_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)) / mclkwas 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.Quoted 5 lines
Issue identified by coccicheck using
do_div.cocci.Changes in v2:
- Replaced explicit(u64)(1 << 27)withBIT_ULL(27)as suggested by Andy Shevchenko.
- Kept original arithmetic logic(mclk / 4)to preserve behavior.Quoted 9 lines
The place for changelog (and comments)...
Quoted 2 lines
Signed-off-by Archit Anant <[email protected]>---
...is here.
But do not resend until maintainers explicitly ask for that.
Tweaked commit message as Andy pointed out was needed.
Quoted 8 lines
Quoted 4 lines
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 <[email protected]>
Added. Thanks,
Quoted 1 line · Jonathan Cameron
...
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Tweaked commit message as Andy pointed out was needed.
Applied to the togreg branch of iio.git
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
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 <[email protected]>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.
Signature · 2 lines
Sincerely, Archit Anant