Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/msm/dpu: change _dpu_plane_calc_bw() to use u64 to avoid overflow

_dpu_plane_calc_bw() uses integer variables to calculate the bandwidth
used during plane bandwidth calculations. However for high resolution
displays this overflows easily and leads to below errors

[dpu error]crtc83 failed performance check -7

Promote the intermediate variables to u64 to avoid overflow.

changes in v2:
- change to u64 where actually needed in the math

Fixes: c33b7c0389e1 ("drm/msm/dpu: add support for clk and bw scaling for display")
Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
Reported-by: Nia Espera <nespera@igalia.com>
Closes: https://gitlab.freedesktop.org/drm/msm/-/issues/32
Tested-by: Nia Espera <nespera@igalia.com>
Patchwork: https://patchwork.freedesktop.org/patch/556288/
Link: https://lore.kernel.org/r/20230908012616.20654-1-quic_abhinavk@quicinc.com
Signed-off-by: Abhinav Kumar <quic_abhinavk@quicinc.com>

+6 -6
+6 -6
drivers/gpu/drm/msm/disp/dpu1/dpu_plane.c
··· 119 119 struct dpu_sw_pipe_cfg *pipe_cfg) 120 120 { 121 121 int src_width, src_height, dst_height, fps; 122 + u64 plane_pixel_rate, plane_bit_rate; 122 123 u64 plane_prefill_bw; 123 124 u64 plane_bw; 124 125 u32 hw_latency_lines; ··· 137 136 scale_factor = src_height > dst_height ? 138 137 mult_frac(src_height, 1, dst_height) : 1; 139 138 140 - plane_bw = 141 - src_width * mode->vtotal * fps * fmt->bpp * 142 - scale_factor; 139 + plane_pixel_rate = src_width * mode->vtotal * fps; 140 + plane_bit_rate = plane_pixel_rate * fmt->bpp; 143 141 144 - plane_prefill_bw = 145 - src_width * hw_latency_lines * fps * fmt->bpp * 146 - scale_factor * mode->vtotal; 142 + plane_bw = plane_bit_rate * scale_factor; 143 + 144 + plane_prefill_bw = plane_bw * hw_latency_lines; 147 145 148 146 if ((vbp+vpw) > hw_latency_lines) 149 147 do_div(plane_prefill_bw, (vbp+vpw));