gpu: drm: msm: use div64_u64() instead of do_div()
Subsystems (4)
PATCH 1/1 gpu: drm: msm: use div64_u64() instead of do_div()
From: Wang Qing <[email protected]>
do_div() does a 64-by-32 division.
When the divisor is u64, do_div() truncates it to 32 bits, this means it can test non-zero and be truncated to zero for division.
fix do_div.cocci warning:do_div() does a 64-by-32 division, please consider using div64_u64 instead.
--- drivers/gpu/drm/msm/msm_gpu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/msm/msm_gpu.c +1 -1
@@ -648,7 +648,7 @@ static void retire_submit(struct msm_gpu *gpu, struct msm_ringbuffer *ring,/* Calculate the clock frequency from the number of CP cycles */ if (elapsed) { clock = (stats->cpcycles_end - stats->cpcycles_start) *1000 ; -do_div (clock, elapsed); +div64_u64 (clock, elapsed); } trace_msm_gpu_submit_retired(submit, elapsed, clock,
Signature · 1 line
2.7.4
Quoted 10 lines · Qing Wang
From: Wang Qing <[email protected]>
do_div()does a 64-by-32 division.
When the divisor is u64,do_div()truncates it to 32 bits, this means it can test non-zero and be truncated to zero for division.fix
do_div.cocciwarning:do_div()does a 64-by-32 division, please consider usingdiv64_u64instead.Signed-off-by Wang Qing <[email protected]>
Quoted 17 lines
--- drivers/gpu/drm/msm/msm_gpu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/msm/msm_gpu.c +1
-1@@ -648,7 +648,7 @@ static void retire_submit(struct msm_gpu *gpu, struct msm_ringbuffer *ring,/* Calculate the clock frequency from the number of CP cycles */ if (elapsed) { clock = (stats->cpcycles_end - stats->cpcycles_start) *1000 ; -do_div (clock, elapsed); +div64_u64 (clock, elapsed); } trace_msm_gpu_submit_retired(submit, elapsed, clock,
Signature · 2 lines
With best wishes Dmitry
Quoted 7 lines · Dmitry Baryshkov
Quoted 6 lines · Qing Wang
From: Wang Qing <[email protected]>
do_div()does a 64-by-32 division.
When the divisor is u64,do_div()truncates it to 32 bits, this means it can test non-zero and be truncated to zero for division.
Quoted 6 lines
Quoted 4 lines
fix
do_div.cocciwarning:do_div()does a 64-by-32 division, please consider usingdiv64_u64instead.Signed-off-by Wang Qing <[email protected]>Reviewed-by Dmitry Baryshkov <[email protected]>
After rechecking, I'd like to withdraw my R-B tag (Minecrell, thanks for pointing this out!)
The div64_u64 is not equivalent to do_div. It returns the quotient rather than modifying the first arg. Moreover it is unoptimal on 32-bit arches.
I'd suggest changing the math to remove multiplications by 1000 and 10000 before division. Or just ignoring this at all, judging from the fact that these values are used only for tracing rather than actual calculations.
Quoted 20 lines
Quoted 18 lines
---
drivers/gpu/drm/msm/msm_gpu.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/msm/msm_gpu.c +1
-1@@ -648,7 +648,7 @@ static void retire_submit(struct msm_gpu *gpu,struct msm_ringbuffer *ring, /* Calculate the clock frequency from the number of CP cycles */ if (elapsed) { clock = (stats->cpcycles_end - stats->cpcycles_start) * 1000; - do_div(clock, elapsed); + div64_u64(clock, elapsed); } trace_msm_gpu_submit_retired(submit, elapsed, clock,
Signature · 2 lines
With best wishes Dmitry