linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] drm/pl111: Use 64-bit arithmetic instead of 32-bit
@ 2018-07-04 14:22 Gustavo A. R. Silva
  2018-07-17 18:40 ` Eric Anholt
  0 siblings, 1 reply; 3+ messages in thread
From: Gustavo A. R. Silva @ 2018-07-04 14:22 UTC (permalink / raw)
  To: Eric Anholt, David Airlie; +Cc: dri-devel, linux-kernel, Gustavo A. R. Silva

Add suffix ULL to constant 1000 in order to give the compiler complete
information about the proper arithmetic to use.

Notice that such constant is used in a context that expects an
expression of type u64 (64 bits, unsigned) and the following
expression is currently being evaluated using 32-bit arithmetic:

mode->clock * 1000

Addresses-Coverity-ID: 1466139 ("Unintentional integer overflow")
Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
---
Changes in v2:
 - Use suffix ULL instead of UL.

 drivers/gpu/drm/pl111/pl111_display.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/pl111/pl111_display.c b/drivers/gpu/drm/pl111/pl111_display.c
index a432eb7..754f6b2 100644
--- a/drivers/gpu/drm/pl111/pl111_display.c
+++ b/drivers/gpu/drm/pl111/pl111_display.c
@@ -63,7 +63,7 @@ pl111_mode_valid(struct drm_crtc *crtc,
 	 * We use the pixelclock to also account for interlaced modes, the
 	 * resulting bandwidth is in bytes per second.
 	 */
-	bw = mode->clock * 1000; /* In Hz */
+	bw = mode->clock * 1000ULL; /* In Hz */
 	bw = bw * mode->hdisplay * mode->vdisplay * cpp;
 	bw = div_u64(bw, mode->htotal * mode->vtotal);
 
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] drm/pl111: Use 64-bit arithmetic instead of 32-bit
  2018-07-04 14:22 [PATCH v2] drm/pl111: Use 64-bit arithmetic instead of 32-bit Gustavo A. R. Silva
@ 2018-07-17 18:40 ` Eric Anholt
  2018-07-17 19:52   ` Gustavo A. R. Silva
  0 siblings, 1 reply; 3+ messages in thread
From: Eric Anholt @ 2018-07-17 18:40 UTC (permalink / raw)
  To: Gustavo A. R. Silva, David Airlie
  Cc: dri-devel, linux-kernel, Gustavo A. R. Silva

[-- Attachment #1: Type: text/plain, Size: 763 bytes --]

"Gustavo A. R. Silva" <gustavo@embeddedor.com> writes:

> Add suffix ULL to constant 1000 in order to give the compiler complete
> information about the proper arithmetic to use.
>
> Notice that such constant is used in a context that expects an
> expression of type u64 (64 bits, unsigned) and the following
> expression is currently being evaluated using 32-bit arithmetic:
>
> mode->clock * 1000
>
> Addresses-Coverity-ID: 1466139 ("Unintentional integer overflow")
> Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>

This is silly.  The clock won't be over 4ghz -- we haven't seen anything
over 1024x768 on this hardware as far as I know.  The u64 is for the
multiplication by width/height below.

I've still applied the patch to shut up the tool.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] drm/pl111: Use 64-bit arithmetic instead of 32-bit
  2018-07-17 18:40 ` Eric Anholt
@ 2018-07-17 19:52   ` Gustavo A. R. Silva
  0 siblings, 0 replies; 3+ messages in thread
From: Gustavo A. R. Silva @ 2018-07-17 19:52 UTC (permalink / raw)
  To: Eric Anholt, David Airlie; +Cc: dri-devel, linux-kernel

Hi Eric,

On 07/17/2018 01:40 PM, Eric Anholt wrote:
> "Gustavo A. R. Silva" <gustavo@embeddedor.com> writes:
> 
>> Add suffix ULL to constant 1000 in order to give the compiler complete
>> information about the proper arithmetic to use.
>>
>> Notice that such constant is used in a context that expects an
>> expression of type u64 (64 bits, unsigned) and the following
>> expression is currently being evaluated using 32-bit arithmetic:
>>
>> mode->clock * 1000
>>
>> Addresses-Coverity-ID: 1466139 ("Unintentional integer overflow")
>> Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
> 
> This is silly.  The clock won't be over 4ghz -- we haven't seen anything
> over 1024x768 on this hardware as far as I know.  The u64 is for the
> multiplication by width/height below.
> 

Yep. I understand. That's why I didn't use the word *fix* anywhere in
the changelog.

> I've still applied the patch to shut up the tool.
> 

Thanks
--
Gustavo

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-07-17 19:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-04 14:22 [PATCH v2] drm/pl111: Use 64-bit arithmetic instead of 32-bit Gustavo A. R. Silva
2018-07-17 18:40 ` Eric Anholt
2018-07-17 19:52   ` Gustavo A. R. Silva

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).