Re: [PATCH] iio: frequency: ad983x: replace do_div() with div64_ul().

From: Andy Shevchenko

Date: Fri Apr 10 2026 - 00:30:21 EST


On Thu, Apr 09, 2026 at 09:58:20PM +0200, Joshua Crofts wrote:
> On Thu, 9 Apr 2026 at 19:27, David Laight <david.laight.linux@xxxxxxxxx> wrote:
> > Except here you have clock frequencies.
> > Either they fit in 32bits or they don't.
> > So the value shouldn't be 'unsigned long', but either u32 or u64.
>
> The clk struct in linux/clk.h explicitly uses an unsigned long to represent
> the clock value, which is used in this driver. Using an unsigned long
> ensures platform independent usage without type mismatching.

...which effectively means the frequency most likely fits 32-bit. Otherwise
would it ever work on 32-bit platform? This is a mistake in CLK design.

> > You need to check the domain of the values, coccinelle is just looking
> > at the types.
> > Even with mclk being 'unsigned long' the code is fine provided the
> > frequency is below 4.2GHz.
>
> I agree that we're not dealing with potential truncation problems, however
> changing to div64_ul aligns the types with the clk API and scrubs a perfectly
> valid cocci error.

--
With Best Regards,
Andy Shevchenko