linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] drm/komeda: fix 32-bit komeda_crtc_update_clock_ratio
@ 2019-06-17 12:51 Arnd Bergmann
  2019-06-17 13:33 ` Liviu Dudau
  2019-06-18  2:05 ` james qian wang (Arm Technology China)
  0 siblings, 2 replies; 3+ messages in thread
From: Arnd Bergmann @ 2019-06-17 12:51 UTC (permalink / raw)
  To: James (Qian) Wang, Liviu Dudau, Brian Starkey, David Airlie,
	Daniel Vetter
  Cc: Arnd Bergmann, Lowry Li (Arm Technology China), dri-devel, linux-kernel

clang points out a bug in the clock calculation on 32-bit, that leads
to the clock_ratio always being zero:

drivers/gpu/drm/arm/display/komeda/komeda_crtc.c:31:36: error: shift count >= width of type [-Werror,-Wshift-count-overflow]
        aclk = komeda_calc_aclk(kcrtc_st) << 32;

Move the shift into the division to make it apply on a 64-bit
variable. Also use the more expensive div64_u64() instead of div_u64()
to account for pxlclk being a 64-bit integer.

Fixes: a962091227ed ("drm/komeda: Add engine clock requirement check for the downscaling")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 drivers/gpu/drm/arm/display/komeda/komeda_crtc.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_crtc.c b/drivers/gpu/drm/arm/display/komeda/komeda_crtc.c
index cafb4457e187..3f222f464eb2 100644
--- a/drivers/gpu/drm/arm/display/komeda/komeda_crtc.c
+++ b/drivers/gpu/drm/arm/display/komeda/komeda_crtc.c
@@ -28,10 +28,9 @@ static void komeda_crtc_update_clock_ratio(struct komeda_crtc_state *kcrtc_st)
 	}
 
 	pxlclk = kcrtc_st->base.adjusted_mode.clock * 1000;
-	aclk = komeda_calc_aclk(kcrtc_st) << 32;
+	aclk = komeda_calc_aclk(kcrtc_st);
 
-	do_div(aclk, pxlclk);
-	kcrtc_st->clock_ratio = aclk;
+	kcrtc_st->clock_ratio = div64_u64(aclk << 32, pxlclk);
 }
 
 /**
-- 
2.20.0


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

* Re: [PATCH] drm/komeda: fix 32-bit komeda_crtc_update_clock_ratio
  2019-06-17 12:51 [PATCH] drm/komeda: fix 32-bit komeda_crtc_update_clock_ratio Arnd Bergmann
@ 2019-06-17 13:33 ` Liviu Dudau
  2019-06-18  2:05 ` james qian wang (Arm Technology China)
  1 sibling, 0 replies; 3+ messages in thread
From: Liviu Dudau @ 2019-06-17 13:33 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: James (Qian) Wang, Brian Starkey, David Airlie, Daniel Vetter,
	Lowry Li (Arm Technology China),
	dri-devel, linux-kernel

On Mon, Jun 17, 2019 at 02:51:04PM +0200, Arnd Bergmann wrote:
> clang points out a bug in the clock calculation on 32-bit, that leads
> to the clock_ratio always being zero:
> 
> drivers/gpu/drm/arm/display/komeda/komeda_crtc.c:31:36: error: shift count >= width of type [-Werror,-Wshift-count-overflow]
>         aclk = komeda_calc_aclk(kcrtc_st) << 32;
> 
> Move the shift into the division to make it apply on a 64-bit
> variable. Also use the more expensive div64_u64() instead of div_u64()
> to account for pxlclk being a 64-bit integer.
> 
> Fixes: a962091227ed ("drm/komeda: Add engine clock requirement check for the downscaling")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

Acked-by: Liviu Dudau <liviu.dudau@arm.com>

Thanks for the patch, I will pull it into the komeda tree.

Best regards,
Liviu

> ---
>  drivers/gpu/drm/arm/display/komeda/komeda_crtc.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_crtc.c b/drivers/gpu/drm/arm/display/komeda/komeda_crtc.c
> index cafb4457e187..3f222f464eb2 100644
> --- a/drivers/gpu/drm/arm/display/komeda/komeda_crtc.c
> +++ b/drivers/gpu/drm/arm/display/komeda/komeda_crtc.c
> @@ -28,10 +28,9 @@ static void komeda_crtc_update_clock_ratio(struct komeda_crtc_state *kcrtc_st)
>  	}
>  
>  	pxlclk = kcrtc_st->base.adjusted_mode.clock * 1000;
> -	aclk = komeda_calc_aclk(kcrtc_st) << 32;
> +	aclk = komeda_calc_aclk(kcrtc_st);
>  
> -	do_div(aclk, pxlclk);
> -	kcrtc_st->clock_ratio = aclk;
> +	kcrtc_st->clock_ratio = div64_u64(aclk << 32, pxlclk);
>  }
>  
>  /**
> -- 
> 2.20.0
> 

-- 
====================
| I would like to |
| fix the world,  |
| but they're not |
| giving me the   |
 \ source code!  /
  ---------------
    ¯\_(ツ)_/¯

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

* Re: [PATCH] drm/komeda: fix 32-bit komeda_crtc_update_clock_ratio
  2019-06-17 12:51 [PATCH] drm/komeda: fix 32-bit komeda_crtc_update_clock_ratio Arnd Bergmann
  2019-06-17 13:33 ` Liviu Dudau
@ 2019-06-18  2:05 ` james qian wang (Arm Technology China)
  1 sibling, 0 replies; 3+ messages in thread
From: james qian wang (Arm Technology China) @ 2019-06-18  2:05 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Liviu Dudau, Brian Starkey, David Airlie, Daniel Vetter,
	Lowry Li (Arm Technology China),
	dri-devel, linux-kernel, nd

On Mon, Jun 17, 2019 at 02:51:04PM +0200, Arnd Bergmann wrote:
> clang points out a bug in the clock calculation on 32-bit, that leads
> to the clock_ratio always being zero:
> 
> drivers/gpu/drm/arm/display/komeda/komeda_crtc.c:31:36: error: shift count >= width of type [-Werror,-Wshift-count-overflow]
>         aclk = komeda_calc_aclk(kcrtc_st) << 32;
> 
> Move the shift into the division to make it apply on a 64-bit
> variable. Also use the more expensive div64_u64() instead of div_u64()
> to account for pxlclk being a 64-bit integer.
> 
> Fixes: a962091227ed ("drm/komeda: Add engine clock requirement check for the downscaling")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
>  drivers/gpu/drm/arm/display/komeda/komeda_crtc.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_crtc.c b/drivers/gpu/drm/arm/display/komeda/komeda_crtc.c
> index cafb4457e187..3f222f464eb2 100644
> --- a/drivers/gpu/drm/arm/display/komeda/komeda_crtc.c
> +++ b/drivers/gpu/drm/arm/display/komeda/komeda_crtc.c
> @@ -28,10 +28,9 @@ static void komeda_crtc_update_clock_ratio(struct komeda_crtc_state *kcrtc_st)
>  	}
>  
>  	pxlclk = kcrtc_st->base.adjusted_mode.clock * 1000;
> -	aclk = komeda_calc_aclk(kcrtc_st) << 32;
> +	aclk = komeda_calc_aclk(kcrtc_st);
>  
> -	do_div(aclk, pxlclk);
> -	kcrtc_st->clock_ratio = aclk;
> +	kcrtc_st->clock_ratio = div64_u64(aclk << 32, pxlclk);
>  }
>  
>  /**
> -- 
> 2.20.0

Hi Arnd:

Thank you for the patch.

Reviewed-by: James Qian Wang (Arm Technology China) <james.qian.wang@arm.com>

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

end of thread, other threads:[~2019-06-18  2:05 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-17 12:51 [PATCH] drm/komeda: fix 32-bit komeda_crtc_update_clock_ratio Arnd Bergmann
2019-06-17 13:33 ` Liviu Dudau
2019-06-18  2:05 ` james qian wang (Arm Technology China)

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