aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSean Paul <seanpaul@chromium.org>2018-10-04 15:24:04 -0400
committerRob Clark <robdclark@gmail.com>2018-10-07 14:40:28 -0400
commitf926a2e1718edc28f59f1079ebb6832532810587 (patch)
tree12c10d41608dc20399d13c5cab357bf61b254c5e
parenta69c5ed25d71c6342fbc6a52fb09b679456394e3 (diff)
drm/msm: a5xx: Fix improper u64 division
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 <smasetty@codeaurora.org> Signed-off-by: Sean Paul <seanpaul@chromium.org> Signed-off-by: Rob Clark <robdclark@gmail.com>
-rw-r--r--drivers/gpu/drm/msm/adreno/a5xx_gpu.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/drivers/gpu/drm/msm/adreno/a5xx_gpu.c b/drivers/gpu/drm/msm/adreno/a5xx_gpu.c
index 40b4f8a0ae6d..eabe9252ae1e 100644
--- a/drivers/gpu/drm/msm/adreno/a5xx_gpu.c
+++ b/drivers/gpu/drm/msm/adreno/a5xx_gpu.c
@@ -1438,18 +1438,20 @@ static struct msm_ringbuffer *a5xx_active_ring(struct msm_gpu *gpu)
1438 1438
1439static unsigned long a5xx_gpu_busy(struct msm_gpu *gpu) 1439static unsigned long a5xx_gpu_busy(struct msm_gpu *gpu)
1440{ 1440{
1441 u64 busy_cycles; 1441 u64 busy_cycles, busy_time;
1442 unsigned long busy_time;
1443 1442
1444 busy_cycles = gpu_read64(gpu, REG_A5XX_RBBM_PERFCTR_RBBM_0_LO, 1443 busy_cycles = gpu_read64(gpu, REG_A5XX_RBBM_PERFCTR_RBBM_0_LO,
1445 REG_A5XX_RBBM_PERFCTR_RBBM_0_HI); 1444 REG_A5XX_RBBM_PERFCTR_RBBM_0_HI);
1446 1445
1447 busy_time = (busy_cycles - gpu->devfreq.busy_cycles) / 1446 busy_time = (busy_cycles - gpu->devfreq.busy_cycles);
1448 (clk_get_rate(gpu->core_clk) / 1000000); 1447 do_div(busy_time, (clk_get_rate(gpu->core_clk) / 1000000));
1449 1448
1450 gpu->devfreq.busy_cycles = busy_cycles; 1449 gpu->devfreq.busy_cycles = busy_cycles;
1451 1450
1452 return busy_time; 1451 if (WARN_ON(busy_time > ~0LU))
1452 return ~0LU;
1453
1454 return (unsigned long)busy_time;
1453} 1455}
1454 1456
1455static const struct adreno_gpu_funcs funcs = { 1457static const struct adreno_gpu_funcs funcs = {