From: Pavel Machek <pavel@ucw.cz>
To: Hans Verkuil <hverkuil@xs4all.nl>
Cc: "Gustavo A. R. Silva" <gustavo@embeddedor.com>,
Mauro Carvalho Chehab <mchehab@kernel.org>,
linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
"Gustavo A. R. Silva" <garsilva@embeddedor.com>
Subject: Re: [PATCH v2 8/8] platform: vivid-cec: use 64-bit arithmetic instead of 32-bit
Date: Tue, 13 Feb 2018 21:59:00 +0100 [thread overview]
Message-ID: <20180213205900.GB6185@amd> (raw)
In-Reply-To: <dc931d9d-8cbd-bbd2-0199-b1846e41f274@xs4all.nl>
[-- Attachment #1: Type: text/plain, Size: 2676 bytes --]
On Mon 2018-02-05 22:29:41, Hans Verkuil wrote:
> On 02/05/2018 09:36 PM, Gustavo A. R. Silva wrote:
> > Add suffix ULL to constant 10 in order to give the compiler complete
> > information about the proper arithmetic to use. Notice that this
> > constant is used in a context that expects an expression of type
> > u64 (64 bits, unsigned).
> >
> > The expression len * 10 * CEC_TIM_DATA_BIT_TOTAL is currently being
> > evaluated using 32-bit arithmetic.
> >
> > Also, remove unnecessary parentheses and add a code comment to make it
> > clear what is the reason of the code change.
> >
> > Addresses-Coverity-ID: 1454996
> > Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
> > ---
> > Changes in v2:
> > - Update subject and changelog to better reflect the proposed code changes.
> > - Add suffix ULL to constant instead of casting a variable.
> > - Remove unncessary parentheses.
>
> unncessary -> unnecessary
>
> > - Add code comment.
> >
> > drivers/media/platform/vivid/vivid-cec.c | 11 +++++++++--
> > 1 file changed, 9 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/media/platform/vivid/vivid-cec.c b/drivers/media/platform/vivid/vivid-cec.c
> > index b55d278..614787b 100644
> > --- a/drivers/media/platform/vivid/vivid-cec.c
> > +++ b/drivers/media/platform/vivid/vivid-cec.c
> > @@ -82,8 +82,15 @@ static void vivid_cec_pin_adap_events(struct cec_adapter *adap, ktime_t ts,
> >
> > if (adap == NULL)
> > return;
> > - ts = ktime_sub_us(ts, (CEC_TIM_START_BIT_TOTAL +
> > - len * 10 * CEC_TIM_DATA_BIT_TOTAL));
> > +
> > + /*
> > + * Suffix ULL on constant 10 makes the expression
> > + * CEC_TIM_START_BIT_TOTAL + 10ULL * len * CEC_TIM_DATA_BIT_TOTAL
> > + * be evaluated using 64-bit unsigned arithmetic (u64), which
> > + * is what ktime_sub_us expects as second argument.
> > + */
>
> That's not really the comment that I was looking for. It still doesn't
> explain *why* this is needed at all. How about something like this:
>
> /*
> * Add the ULL suffix to the constant 10 to work around a false Coverity
> * "Unintentional integer overflow" warning. Coverity isn't smart enough
> * to understand that len is always <= 16, so there is no chance of an
> * integer overflow.
> */
Or maybe it would be better to add comment about Coverity having
false-positive and not to modify the code?
Hmm. Could we do something like BUG_ON(len > 16) to make Coverity
understand the ranges?
Pavel
--
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 181 bytes --]
prev parent reply other threads:[~2018-02-13 20:59 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-05 20:06 [PATCH v2 0/8] use 64-bit arithmetic instead of 32-bit Gustavo A. R. Silva
2018-02-05 20:06 ` [PATCH v2 1/8] rtl2832: use 64-bit arithmetic instead of 32-bit in rtl2832_set_frontend Gustavo A. R. Silva
2018-02-05 20:06 ` [PATCH v2 2/8] dvb-frontends: ves1820: use 64-bit arithmetic instead of 32-bit Gustavo A. R. Silva
2018-02-05 20:08 ` [PATCH v2 3/8] i2c: max2175: " Gustavo A. R. Silva
2018-02-05 20:08 ` [PATCH v2 4/8] i2c: ov9650: " Gustavo A. R. Silva
2018-02-05 20:27 ` [PATCH v2 5/8] pci: cx88-input: " Gustavo A. R. Silva
2018-02-05 20:27 ` [PATCH v2 6/8] rockchip/rga: " Gustavo A. R. Silva
2018-02-05 20:27 ` [PATCH v2 7/8] platform: sh_veu: " Gustavo A. R. Silva
2018-02-05 20:36 ` [PATCH v2 8/8] platform: vivid-cec: " Gustavo A. R. Silva
2018-02-05 21:29 ` Hans Verkuil
2018-02-05 21:54 ` Gustavo A. R. Silva
2018-02-06 10:41 ` Hans Verkuil
2018-02-06 16:35 ` Gustavo A. R. Silva
2018-02-13 20:59 ` Pavel Machek [this message]
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=20180213205900.GB6185@amd \
--to=pavel@ucw.cz \
--cc=garsilva@embeddedor.com \
--cc=gustavo@embeddedor.com \
--cc=hverkuil@xs4all.nl \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=mchehab@kernel.org \
/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