[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <aXI-ZV4uAd5GyFLz@smile.fi.intel.com>
Date: Thu, 22 Jan 2026 17:12:37 +0200
From: Andy Shevchenko <andriy.shevchenko@...el.com>
To: Archit Anant <architanant5@...il.com>
Cc: jic23@...nel.org, lars@...afoo.de, Michael.Hennerich@...log.com,
gregkh@...uxfoundation.org, dlechner@...libre.com,
nuno.sa@...log.com, andy@...nel.org, linux-iio@...r.kernel.org,
linux-staging@...ts.linux.dev, linux-kernel@...r.kernel.org
Subject: Re: [PATCH] staging: iio: impedance-analyzer: ad5933: use div64_ul()
instead of do_div()
On Thu, Jan 22, 2026 at 08:26:33PM +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, as it returns the result directly rather
> than modifying the dividend in-place.
>
> Issue identified by coccicheck using do_div.cocci.
...
> - freqreg = (u64)freq * (u64)(1 << 27);
> - do_div(freqreg, st->mclk_hz / 4);
> + freqreg = div64_ul((u64)freq * (u64)(1 << 27),
> + st->mclk_hz / 4);
It can be one line to begin with.
Then drop that ugly castings and explicit big shifts.
freqreg = div64_ul(BIT_ULL(27) * freq, st->mclk_hz / 4);
Now you can see That 4 is only 2 bits, so this can be written in
simpler way:
freqreg = div64_ul(BIT_ULL(29) * freq, st->mclk_hz);
which may give a better precision at the end of the day.
--
With Best Regards,
Andy Shevchenko
Powered by blists - more mailing lists