drm/amd/display: Avoid NULL dereference of timing generator
authorWayne Lin <wayne.lin@amd.com>
Fri, 8 Sep 2023 02:14:49 +0000 (10:14 +0800)
committerAlex Deucher <alexander.deucher@amd.com>
Fri, 3 Nov 2023 15:59:51 +0000 (11:59 -0400)
[Why & How]
Check whether assigned timing generator is NULL or not before
accessing its funcs to prevent NULL dereference.

Reviewed-by: Jun Lei <jun.lei@amd.com>
Acked-by: Hersen Wu <hersenxs.wu@amd.com>
Signed-off-by: Wayne Lin <wayne.lin@amd.com>
Tested-by: Daniel Wheeler <daniel.wheeler@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/display/dc/core/dc_stream.c

index 6ed40b6c6178f9c08aeaedb73c48a10d04d23511..4bdf105d1d7150d666bb2a42eccfd940e7a29a39 100644 (file)
@@ -533,7 +533,7 @@ uint32_t dc_stream_get_vblank_counter(const struct dc_stream_state *stream)
        for (i = 0; i < MAX_PIPES; i++) {
                struct timing_generator *tg = res_ctx->pipe_ctx[i].stream_res.tg;
 
-               if (res_ctx->pipe_ctx[i].stream != stream)
+               if (res_ctx->pipe_ctx[i].stream != stream || !tg)
                        continue;
 
                return tg->funcs->get_frame_count(tg);
@@ -592,7 +592,7 @@ bool dc_stream_get_scanoutpos(const struct dc_stream_state *stream,
        for (i = 0; i < MAX_PIPES; i++) {
                struct timing_generator *tg = res_ctx->pipe_ctx[i].stream_res.tg;
 
-               if (res_ctx->pipe_ctx[i].stream != stream)
+               if (res_ctx->pipe_ctx[i].stream != stream || !tg)
                        continue;
 
                tg->funcs->get_scanoutpos(tg,