* [PATCH] staging: iio: Use div64_ul instead of do_div
@ 2022-10-19 5:38 Kang Minchul
2022-10-20 15:27 ` Greg Kroah-Hartman
0 siblings, 1 reply; 2+ messages in thread
From: Kang Minchul @ 2022-10-19 5:38 UTC (permalink / raw)
To: Lars-Peter Clausen, Michael Hennerich, Jonathan Cameron
Cc: Greg Kroah-Hartman, linux-iio, linux-staging, linux-kernel,
Kang Minchul
Using div64_ul instead of do_div (64-by-32 division) is more
recommended by coccicheck because this can avoid potential truncation.
So this commit changes do_div to div64_ul and
remove coccicheck warnings.
Signed-off-by: Kang Minchul <tegongkang@gmail.com>
---
drivers/staging/iio/frequency/ad9832.c | 2 +-
drivers/staging/iio/frequency/ad9834.c | 2 +-
drivers/staging/iio/impedance-analyzer/ad5933.c | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/staging/iio/frequency/ad9832.c b/drivers/staging/iio/frequency/ad9832.c
index 6f9eebd6c7ee..cd038480f63c 100644
--- a/drivers/staging/iio/frequency/ad9832.c
+++ b/drivers/staging/iio/frequency/ad9832.c
@@ -122,7 +122,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);
+ freqreg = div64_ul(freqreg, mclk);
return freqreg;
}
diff --git a/drivers/staging/iio/frequency/ad9834.c b/drivers/staging/iio/frequency/ad9834.c
index 2b4267a87e65..cfe933ef40d0 100644
--- a/drivers/staging/iio/frequency/ad9834.c
+++ b/drivers/staging/iio/frequency/ad9834.c
@@ -102,7 +102,7 @@ static unsigned int ad9834_calc_freqreg(unsigned long mclk, unsigned long fout)
{
unsigned long long freqreg = (u64)fout * (u64)BIT(AD9834_FREQ_BITS);
- do_div(freqreg, mclk);
+ freqreg = div64_ul(freqreg, mclk);
return freqreg;
}
diff --git a/drivers/staging/iio/impedance-analyzer/ad5933.c b/drivers/staging/iio/impedance-analyzer/ad5933.c
index f177b20f0f2d..730bb31a20d8 100644
--- a/drivers/staging/iio/impedance-analyzer/ad5933.c
+++ b/drivers/staging/iio/impedance-analyzer/ad5933.c
@@ -196,7 +196,7 @@ static int ad5933_set_freq(struct ad5933_state *st,
} dat;
freqreg = (u64)freq * (u64)(1 << 27);
- do_div(freqreg, st->mclk_hz / 4);
+ freqreg = div64_ul(freqreg, st->mclk_hz / 4);
switch (reg) {
case AD5933_REG_FREQ_START:
--
2.34.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] staging: iio: Use div64_ul instead of do_div
2022-10-19 5:38 [PATCH] staging: iio: Use div64_ul instead of do_div Kang Minchul
@ 2022-10-20 15:27 ` Greg Kroah-Hartman
0 siblings, 0 replies; 2+ messages in thread
From: Greg Kroah-Hartman @ 2022-10-20 15:27 UTC (permalink / raw)
To: Kang Minchul
Cc: Lars-Peter Clausen, Michael Hennerich, Jonathan Cameron,
linux-iio, linux-staging, linux-kernel
On Wed, Oct 19, 2022 at 02:38:29PM +0900, Kang Minchul wrote:
> Using div64_ul instead of do_div (64-by-32 division) is more
> recommended by coccicheck because this can avoid potential truncation.
>
> So this commit changes do_div to div64_ul and
> remove coccicheck warnings.
>
> Signed-off-by: Kang Minchul <tegongkang@gmail.com>
> ---
> drivers/staging/iio/frequency/ad9832.c | 2 +-
> drivers/staging/iio/frequency/ad9834.c | 2 +-
> drivers/staging/iio/impedance-analyzer/ad5933.c | 2 +-
> 3 files changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/staging/iio/frequency/ad9832.c b/drivers/staging/iio/frequency/ad9832.c
> index 6f9eebd6c7ee..cd038480f63c 100644
> --- a/drivers/staging/iio/frequency/ad9832.c
> +++ b/drivers/staging/iio/frequency/ad9832.c
> @@ -122,7 +122,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);
> + freqreg = div64_ul(freqreg, mclk);
I think the original code here is correct, no need for a change, unless
you have the hardware to test this out and can verify it all still works
identically.
thanks,
greg k-h
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-10-20 15:28 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-10-19 5:38 [PATCH] staging: iio: Use div64_ul instead of do_div Kang Minchul
2022-10-20 15:27 ` Greg Kroah-Hartman
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox