diff options
author | Sean Paul <seanpaul@chromium.org> | 2018-10-04 15:24:04 -0400 |
---|---|---|
committer | Rob Clark <robdclark@gmail.com> | 2018-10-07 14:40:28 -0400 |
commit | f926a2e1718edc28f59f1079ebb6832532810587 (patch) | |
tree | 12c10d41608dc20399d13c5cab357bf61b254c5e /drivers/gpu/drm/msm/adreno/a5xx_gpu.c | |
parent | a69c5ed25d71c6342fbc6a52fb09b679456394e3 (diff) | |
download | lwn-f926a2e1718edc28f59f1079ebb6832532810587.tar.gz lwn-f926a2e1718edc28f59f1079ebb6832532810587.zip |
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>
Diffstat (limited to 'drivers/gpu/drm/msm/adreno/a5xx_gpu.c')
-rw-r--r-- | drivers/gpu/drm/msm/adreno/a5xx_gpu.c | 12 |
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) 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 = { |