Re: [PATCH] staging: iio: frequency: ad9832: Use div64_ul instead of do_div

From: Jonathan Cameron
Date: Sat Oct 29 2022 - 07:59:58 EST


On Fri, 28 Oct 2022 10:11:56 +0000
"Sa, Nuno" <Nuno.Sa@xxxxxxxxxx> wrote:

> > -----Original Message-----
> > From: Deepak R Varma <drv@xxxxxxxxx>
> > Sent: Thursday, October 27, 2022 11:54 PM
> > To: outreachy@xxxxxxxxxxxxxxx; Lars-Peter Clausen <lars@xxxxxxxxxx>;
> > Hennerich, Michael <Michael.Hennerich@xxxxxxxxxx>; Jonathan Cameron
> > <jic23@xxxxxxxxxx>; Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>;
> > linux-iio@xxxxxxxxxxxxxxx; linux-staging@xxxxxxxxxxxxxxx; linux-
> > kernel@xxxxxxxxxxxxxxx
> > Subject: [PATCH] staging: iio: frequency: ad9832: Use div64_ul instead of
> > do_div
> >
> > [External]
> >
> > do_div() does a 64-by-32 division. Here the divisor is an unsigned long
> > which on some platforms is 64 bit wide. So use div64_ul instead of do_div
> > to avoid a possible truncation. Issue identified using the
> > coccicheck tool.
> >
> > Signed-off-by: Deepak R Varma <drv@xxxxxxxxx>
> > ---
>
> Reviewed-by: Nuno Sá <nuno.sa@xxxxxxxxxx>

As per the email Greg linked to, please take a close look at the surround code
and include analysis of whether the value can actually be greater than 32 bits.
Note that in most cases that would actually mean the code was broken on 32 bit
platforms.