linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] drm/rockchip: cdn-dp: fix sign extension on an int multiply for a u64 result
@ 2020-09-15 16:20 Colin King
  2020-09-15 17:29 ` Guenter Roeck
  2021-05-28 18:55 ` Heiko Stuebner
  0 siblings, 2 replies; 3+ messages in thread
From: Colin King @ 2020-09-15 16:20 UTC (permalink / raw)
  To: Sandy Huang, Heiko Stübner, David Airlie, Daniel Vetter,
	Chris Zhong, Guenter Roeck, Sean Paul, dri-devel,
	linux-arm-kernel, linux-rockchip
  Cc: kernel-janitors, linux-kernel

From: Colin Ian King <colin.king@canonical.com>

The variable bit_per_pix is a u8 and is promoted in the multiplication
to an int type and then sign extended to a u64. If the result of the
int multiplication is greater than 0x7fffffff then the upper 32 bits will
be set to 1 as a result of the sign extension. Avoid this by casting
tu_size_reg to u64 to avoid sign extension and also a potential overflow.

Addresses-Coverity: ("Unintended sign extension")
Fixes: 1a0f7ed3abe2 ("drm/rockchip: cdn-dp: add cdn DP support for rk3399")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 drivers/gpu/drm/rockchip/cdn-dp-reg.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/rockchip/cdn-dp-reg.c b/drivers/gpu/drm/rockchip/cdn-dp-reg.c
index 9d2163ef4d6e..33fb4d05c506 100644
--- a/drivers/gpu/drm/rockchip/cdn-dp-reg.c
+++ b/drivers/gpu/drm/rockchip/cdn-dp-reg.c
@@ -658,7 +658,7 @@ int cdn_dp_config_video(struct cdn_dp_device *dp)
 	 */
 	do {
 		tu_size_reg += 2;
-		symbol = tu_size_reg * mode->clock * bit_per_pix;
+		symbol = (u64)tu_size_reg * mode->clock * bit_per_pix;
 		do_div(symbol, dp->max_lanes * link_rate * 8);
 		rem = do_div(symbol, 1000);
 		if (tu_size_reg > 64) {
-- 
2.27.0


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

* Re: [PATCH] drm/rockchip: cdn-dp: fix sign extension on an int multiply for a u64 result
  2020-09-15 16:20 [PATCH] drm/rockchip: cdn-dp: fix sign extension on an int multiply for a u64 result Colin King
@ 2020-09-15 17:29 ` Guenter Roeck
  2021-05-28 18:55 ` Heiko Stuebner
  1 sibling, 0 replies; 3+ messages in thread
From: Guenter Roeck @ 2020-09-15 17:29 UTC (permalink / raw)
  To: Colin King
  Cc: Sandy Huang, Heiko Stübner, David Airlie, Daniel Vetter,
	Chris Zhong, Guenter Roeck, Sean Paul,
	Maling list - DRI developers, moderated list:ARM PORT,
	open list:ARM/Rockchip SoC...,
	kernel-janitors, linux-kernel

On Tue, Sep 15, 2020 at 9:20 AM Colin King <colin.king@canonical.com> wrote:
>
> From: Colin Ian King <colin.king@canonical.com>
>
> The variable bit_per_pix is a u8 and is promoted in the multiplication
> to an int type and then sign extended to a u64. If the result of the
> int multiplication is greater than 0x7fffffff then the upper 32 bits will
> be set to 1 as a result of the sign extension. Avoid this by casting
> tu_size_reg to u64 to avoid sign extension and also a potential overflow.
>
> Addresses-Coverity: ("Unintended sign extension")
> Fixes: 1a0f7ed3abe2 ("drm/rockchip: cdn-dp: add cdn DP support for rk3399")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>

Reviewed-by: Guenter Roeck <groeck@chromium.org>

> ---
>  drivers/gpu/drm/rockchip/cdn-dp-reg.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/rockchip/cdn-dp-reg.c b/drivers/gpu/drm/rockchip/cdn-dp-reg.c
> index 9d2163ef4d6e..33fb4d05c506 100644
> --- a/drivers/gpu/drm/rockchip/cdn-dp-reg.c
> +++ b/drivers/gpu/drm/rockchip/cdn-dp-reg.c
> @@ -658,7 +658,7 @@ int cdn_dp_config_video(struct cdn_dp_device *dp)
>          */
>         do {
>                 tu_size_reg += 2;
> -               symbol = tu_size_reg * mode->clock * bit_per_pix;
> +               symbol = (u64)tu_size_reg * mode->clock * bit_per_pix;
>                 do_div(symbol, dp->max_lanes * link_rate * 8);
>                 rem = do_div(symbol, 1000);
>                 if (tu_size_reg > 64) {
> --
> 2.27.0
>

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

* Re: [PATCH] drm/rockchip: cdn-dp: fix sign extension on an int multiply for a u64 result
  2020-09-15 16:20 [PATCH] drm/rockchip: cdn-dp: fix sign extension on an int multiply for a u64 result Colin King
  2020-09-15 17:29 ` Guenter Roeck
@ 2021-05-28 18:55 ` Heiko Stuebner
  1 sibling, 0 replies; 3+ messages in thread
From: Heiko Stuebner @ 2021-05-28 18:55 UTC (permalink / raw)
  To: Colin King, Chris Zhong, Daniel Vetter, Sandy Huang,
	linux-arm-kernel, Guenter Roeck, Sean Paul, David Airlie,
	dri-devel, linux-rockchip
  Cc: Heiko Stuebner, kernel-janitors, linux-kernel

On Tue, 15 Sep 2020 17:20:49 +0100, Colin King wrote:
> The variable bit_per_pix is a u8 and is promoted in the multiplication
> to an int type and then sign extended to a u64. If the result of the
> int multiplication is greater than 0x7fffffff then the upper 32 bits will
> be set to 1 as a result of the sign extension. Avoid this by casting
> tu_size_reg to u64 to avoid sign extension and also a potential overflow.

Applied, thanks!

[1/1] drm/rockchip: cdn-dp: fix sign extension on an int multiply for a u64 result
      commit: ce0cb93a5adb283f577cd4661f511047b5e39028

Best regards,
-- 
Heiko Stuebner <heiko@sntech.de>

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

end of thread, other threads:[~2021-05-28 18:56 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-15 16:20 [PATCH] drm/rockchip: cdn-dp: fix sign extension on an int multiply for a u64 result Colin King
2020-09-15 17:29 ` Guenter Roeck
2021-05-28 18:55 ` Heiko Stuebner

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