* [PATCH v2] staging: iio: frequency: ad9834: Use div64_ul instead of do_div
@ 2022-10-27 21:59 Deepak R Varma
2022-10-28 10:14 ` Sa, Nuno
0 siblings, 1 reply; 3+ messages in thread
From: Deepak R Varma @ 2022-10-27 21:59 UTC (permalink / raw)
To: outreachy, Lars-Peter Clausen, Michael Hennerich,
Jonathan Cameron, Greg Kroah-Hartman, linux-iio, linux-staging,
linux-kernel
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@mailo.com>
---
Changes in v2:
1. No functional change.
Include outreachy mailing list on the to list
drivers/staging/iio/frequency/ad9834.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/drivers/staging/iio/frequency/ad9834.c b/drivers/staging/iio/frequency/ad9834.c
index 285df0e489a6..3917a76e7976 100644
--- a/drivers/staging/iio/frequency/ad9834.c
+++ b/drivers/staging/iio/frequency/ad9834.c
@@ -102,8 +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);
- return freqreg;
+ return div64_ul(freqreg, mclk);
}
static int ad9834_write_frequency(struct ad9834_state *st,
--
2.34.1
^ permalink raw reply related [flat|nested] 3+ messages in thread* RE: [PATCH v2] staging: iio: frequency: ad9834: Use div64_ul instead of do_div
2022-10-27 21:59 [PATCH v2] staging: iio: frequency: ad9834: Use div64_ul instead of do_div Deepak R Varma
@ 2022-10-28 10:14 ` Sa, Nuno
2022-10-29 12:11 ` Jonathan Cameron
0 siblings, 1 reply; 3+ messages in thread
From: Sa, Nuno @ 2022-10-28 10:14 UTC (permalink / raw)
To: Deepak R Varma, outreachy@lists.linux.dev, Lars-Peter Clausen,
Hennerich, Michael, Jonathan Cameron, Greg Kroah-Hartman,
linux-iio@vger.kernel.org, linux-staging@lists.linux.dev,
linux-kernel@vger.kernel.org
> -----Original Message-----
> From: Deepak R Varma <drv@mailo.com>
> Sent: Friday, October 28, 2022 12:00 AM
> To: outreachy@lists.linux.dev; Lars-Peter Clausen <lars@metafoo.de>;
> Hennerich, Michael <Michael.Hennerich@analog.com>; Jonathan Cameron
> <jic23@kernel.org>; Greg Kroah-Hartman <gregkh@linuxfoundation.org>;
> linux-iio@vger.kernel.org; linux-staging@lists.linux.dev; linux-
> kernel@vger.kernel.org
> Subject: [PATCH v2] staging: iio: frequency: ad9834: 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@mailo.com>
> ---
Clearly, I should have looked better and only reply to this one:
Reviewed-by: Nuno Sá <nuno.sa@analog.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] staging: iio: frequency: ad9834: Use div64_ul instead of do_div
2022-10-28 10:14 ` Sa, Nuno
@ 2022-10-29 12:11 ` Jonathan Cameron
0 siblings, 0 replies; 3+ messages in thread
From: Jonathan Cameron @ 2022-10-29 12:11 UTC (permalink / raw)
To: Sa, Nuno
Cc: Deepak R Varma, outreachy@lists.linux.dev, Lars-Peter Clausen,
Hennerich, Michael, Greg Kroah-Hartman, linux-iio@vger.kernel.org,
linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org
On Fri, 28 Oct 2022 10:14:48 +0000
"Sa, Nuno" <Nuno.Sa@analog.com> wrote:
> > -----Original Message-----
> > From: Deepak R Varma <drv@mailo.com>
> > Sent: Friday, October 28, 2022 12:00 AM
> > To: outreachy@lists.linux.dev; Lars-Peter Clausen <lars@metafoo.de>;
> > Hennerich, Michael <Michael.Hennerich@analog.com>; Jonathan Cameron
> > <jic23@kernel.org>; Greg Kroah-Hartman <gregkh@linuxfoundation.org>;
> > linux-iio@vger.kernel.org; linux-staging@lists.linux.dev; linux-
> > kernel@vger.kernel.org
> > Subject: [PATCH v2] staging: iio: frequency: ad9834: 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@mailo.com>
> > ---
>
> Clearly, I should have looked better and only reply to this one:
>
> Reviewed-by: Nuno Sá <nuno.sa@analog.com>
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.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-10-29 11:59 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-10-27 21:59 [PATCH v2] staging: iio: frequency: ad9834: Use div64_ul instead of do_div Deepak R Varma
2022-10-28 10:14 ` Sa, Nuno
2022-10-29 12:11 ` Jonathan Cameron
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox