Skip to contentSkip to conversation

drm/msm: a5xx: Fix improper u64 division

PATCH Superseded Sean Paul 1 participant 1 message Oct 4, 2018

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Sean Paul

author
#0 lore raw

PATCH 1/1 drm/msm: a5xx: Fix improper u64 division

From: Sean Paul <[email protected]>

This patch uses the proper do_div() macro to perform u64 division and guards against overflow if the result is too large for the unsigned long return type

Fixes de0a3d094de0 drm/msm: re-factor devfreq code
Cc Sharat Masetty <[email protected]>
---
 drivers/gpu/drm/msm/adreno/a5xx_gpu.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
drivers/gpu/drm/msm/adreno/a5xx_gpu.c +7 -5
index 40b4f8a0ae6d..eabe9252ae1e 100644
@@ -1438,18 +1438,20 @@ static struct msm_ringbuffer *a5xx_active_ring(struct msm_gpu *gpu)
 
 static unsigned long a5xx_gpu_busy(struct msm_gpu *gpu)
 {
-	u64 busy_cycles;
-	unsigned long busy_time;
+	u64 busy_cycles, busy_time;
 
 	busy_cycles = gpu_read64(gpu, REG_A5XX_RBBM_PERFCTR_RBBM_0_LO,
 			REG_A5XX_RBBM_PERFCTR_RBBM_0_HI);
 
-	busy_time = (busy_cycles - gpu->devfreq.busy_cycles) /
-		(clk_get_rate(gpu->core_clk) / 1000000);
+	busy_time = (busy_cycles - gpu->devfreq.busy_cycles);
+	do_div(busy_time, (clk_get_rate(gpu->core_clk) / 1000000));
 
 	gpu->devfreq.busy_cycles = busy_cycles;
 
-	return busy_time;
+	if (WARN_ON(busy_time > ~0LU))
+		return ~0LU;
+
+	return (unsigned long)busy_time;
 }
 
 static const struct adreno_gpu_funcs funcs = {
Signature · 6 lines
Sean Paul, Software Engineer, Google / Chromium OS

_______________________________________________
Freedreno mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/freedreno