From: David Laight <David.Laight@ACULAB.COM>
To: "'Sa, Nuno'" <Nuno.Sa@analog.com>, Deepak R Varma <drv@mailo.com>,
"outreachy@lists.linux.dev" <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-iio@vger.kernel.org>,
"linux-staging@lists.linux.dev" <linux-staging@lists.linux.dev>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: RE: [PATCH] staging: iio: ad5933: Use div64_ul instead of do_div
Date: Sat, 29 Oct 2022 11:23:06 +0000 [thread overview]
Message-ID: <5740bcb3490d4c17bd9bc731e79b174b@AcuMS.aculab.com> (raw)
In-Reply-To: <SJ0PR03MB6778EAAB4132374270E96FFB99329@SJ0PR03MB6778.namprd03.prod.outlook.com>
> > -----Original Message-----
> > From: Deepak R Varma <drv@mailo.com>
> >
> > [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 was identified using the
> > coccicheck tool.
These changes should all get nacked unless the domain of the values
can be shown to be out of range.
The entire point of do_div() is that because division is expensive
using a limited range division is significantly faster.
Even on Intel 64 bit cpu the 64 by 32 divide is significantly
faster then a full 64 bit divide for the same input values.
One might also question why the divisor is actually 'unsigned long'
at all. The code is almost certainly expected to compile for 32bit
so the domain of the value should fit in 32 bits.
So either the type could be unsigned int, or it really doesn't matter
that the value is truncated to 32bit because it can never be larger.
David
> >
> > Signed-off-by: Deepak R Varma <drv@mailo.com>
> > ---
>
> Reviewed-by: Nuno Sá <nuno.sa@analog.com>
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
next prev parent reply other threads:[~2022-10-29 11:23 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-27 21:28 [PATCH] staging: iio: ad5933: Use div64_ul instead of do_div Deepak R Varma
2022-10-28 10:11 ` Sa, Nuno
2022-10-29 11:23 ` David Laight [this message]
2022-11-04 18:47 ` Deepak R Varma
2022-10-29 7:52 ` Greg Kroah-Hartman
2022-10-31 10:06 ` Deepak R Varma
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5740bcb3490d4c17bd9bc731e79b174b@AcuMS.aculab.com \
--to=david.laight@aculab.com \
--cc=Michael.Hennerich@analog.com \
--cc=Nuno.Sa@analog.com \
--cc=drv@mailo.com \
--cc=gregkh@linuxfoundation.org \
--cc=jic23@kernel.org \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-staging@lists.linux.dev \
--cc=outreachy@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox