From: Robin Murphy <robin.murphy@arm.com>
To: Ming Qian <ming.qian@nxp.com>,
David Laight <David.Laight@ACULAB.COM>,
"mchehab@kernel.org" <mchehab@kernel.org>,
"shawnguo@kernel.org" <shawnguo@kernel.org>,
"robh+dt@kernel.org" <robh+dt@kernel.org>,
"s.hauer@pengutronix.de" <s.hauer@pengutronix.de>
Cc: "hverkuil-cisco@xs4all.nl" <hverkuil-cisco@xs4all.nl>,
"kernel@pengutronix.de" <kernel@pengutronix.de>,
"festevam@gmail.com" <festevam@gmail.com>,
dl-linux-imx <linux-imx@nxp.com>,
Aisheng Dong <aisheng.dong@nxp.com>,
"linux-media@vger.kernel.org" <linux-media@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"devicetree@vger.kernel.org" <devicetree@vger.kernel.org>,
"linux-arm-kernel@lists.infradead.org"
<linux-arm-kernel@lists.infradead.org>
Subject: Re: [EXT] RE: [PATCH] media: amphion: fix some error related with undefined reference to __divdi3
Date: Thu, 10 Mar 2022 11:31:41 +0000 [thread overview]
Message-ID: <3021738c-06e4-6760-5a70-5b3dc57f1e96@arm.com> (raw)
In-Reply-To: <AM6PR04MB63417FD1C3EE77BBE1649B47E70B9@AM6PR04MB6341.eurprd04.prod.outlook.com>
On 2022-03-10 08:36, Ming Qian wrote:
>> -----Original Message-----
>> From: David Laight [mailto:David.Laight@ACULAB.COM]
>> Sent: Wednesday, March 9, 2022 9:27 PM
>> To: Ming Qian <ming.qian@nxp.com>; mchehab@kernel.org;
>> shawnguo@kernel.org; robh+dt@kernel.org; s.hauer@pengutronix.de
>> Cc: hverkuil-cisco@xs4all.nl; kernel@pengutronix.de; festevam@gmail.com;
>> dl-linux-imx <linux-imx@nxp.com>; Aisheng Dong <aisheng.dong@nxp.com>;
>> linux-media@vger.kernel.org; linux-kernel@vger.kernel.org;
>> devicetree@vger.kernel.org; linux-arm-kernel@lists.infradead.org
>> Subject: [EXT] RE: [PATCH] media: amphion: fix some error related with
>> undefined reference to __divdi3
>>
>> Caution: EXT Email
>>
>> From: Ming Qian
>>> Sent: 09 March 2022 05:02
>> ...
>>> 3. use 'val >> 1' instead of ' val / 2'
>>
>> The compiler should do that anyway.
>>
>> Especially for unsigned values.
>> And it has the wrong (different) rounding for negative values.
>>
>> David
>>
>
> Hi David,
> Yes, you are right, if the value is negative, the behavior is wrong.
> But here, the value type is u32, so I think it's OK.
Well, it depends on the semantic intent, really. If you're packing a
bitfield which encodes bits 31:1 of some value then a shift is the most
appropriate operation. However if you're literally calculating half of a
value for, say, a 50% threshold level, or the number of 16-bit words
represented by a byte length, then semantically it's a division, so it
should use the divide operator rather than obfuscating it behind a
shift. Constant division is something that even the most basic
optimising compiler should handle with ease.
One more thing that's not the fault of this patch, but stood out in the
context:
@@ -1566,7 +1568,7 @@ static bool vpu_malone_check_ready(struct
vpu_shared_addr *shared, u32 instance)
u32 wptr = desc->wptr;
u32 used = (wptr + size - rptr) % size;
- if (!size || used < size / 2)
+ if (!size || used < (size >> 1))
return true;
return false;
That's not safe: if "size" is 0 then the undefined behaviour has already
happened before the "!size" check is reached. If "size" really can be 0,
then it needs to be checked *before* it is used as a divisor to
calculate "used".
Robin.
next prev parent reply other threads:[~2022-03-10 11:31 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-09 5:02 [PATCH] media: amphion: fix some error related with undefined reference to __divdi3 Ming Qian
2022-03-09 13:27 ` David Laight
2022-03-10 8:36 ` [EXT] " Ming Qian
2022-03-10 11:31 ` Robin Murphy [this message]
2022-03-10 13:44 ` 回复: " Ming Qian
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=3021738c-06e4-6760-5a70-5b3dc57f1e96@arm.com \
--to=robin.murphy@arm.com \
--cc=David.Laight@ACULAB.COM \
--cc=aisheng.dong@nxp.com \
--cc=devicetree@vger.kernel.org \
--cc=festevam@gmail.com \
--cc=hverkuil-cisco@xs4all.nl \
--cc=kernel@pengutronix.de \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-imx@nxp.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=mchehab@kernel.org \
--cc=ming.qian@nxp.com \
--cc=robh+dt@kernel.org \
--cc=s.hauer@pengutronix.de \
--cc=shawnguo@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;
as well as URLs for NNTP newsgroup(s).