diff options
author | Rodrigo Siqueira <[email protected]> | 2024-05-29 08:57:02 -0600 |
---|---|---|
committer | Alex Deucher <[email protected]> | 2024-06-14 16:17:17 -0400 |
commit | 9d8152cd1be1c1049dc7d70e2f0a01989d1d9a17 (patch) | |
tree | 24b4470b71aa58738a7d7e95ab3e26fb3c6a6e33 | |
parent | 7c70e60fbf4bff1123f0e8d5cb1ae71df6164d7f (diff) |
drm/amd/display: Check otg_master pointer before use it
Coverity highlighted that the parameter otg_master is referenced before
the if condition that validates it, which means that the code might have
some attempt to access a null pointer. This commit addresses this issue
by moving the pointer verification to the beginning of the function and
initializing all the values right after it.
Acked-by: Zaeem Mohamed <[email protected]>
Signed-off-by: Rodrigo Siqueira <[email protected]>
Tested-by: Daniel Wheeler <[email protected]>
Signed-off-by: Alex Deucher <[email protected]>
-rw-r--r-- | drivers/gpu/drm/amd/display/dc/core/dc_resource.c | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/drivers/gpu/drm/amd/display/dc/core/dc_resource.c b/drivers/gpu/drm/amd/display/dc/core/dc_resource.c index 7894d3e52a27..e047ea4ff3aa 100644 --- a/drivers/gpu/drm/amd/display/dc/core/dc_resource.c +++ b/drivers/gpu/drm/amd/display/dc/core/dc_resource.c @@ -2077,15 +2077,23 @@ int resource_get_odm_slice_index(const struct pipe_ctx *pipe_ctx) int resource_get_odm_slice_dst_width(struct pipe_ctx *otg_master, bool is_last_segment) { - const struct dc_crtc_timing *timing = &otg_master->stream->timing; - int count = resource_get_odm_slice_count(otg_master); - int h_active = timing->h_addressable + - timing->h_border_left + - timing->h_border_right; - int width = h_active / count; + const struct dc_crtc_timing *timing; + int count; + int h_active; + int width; bool two_pixel_alignment_required = false; - if (otg_master && otg_master->stream_res.tg && otg_master->stream) + if (!otg_master || !otg_master->stream) + return 0; + + timing = &otg_master->stream->timing; + count = resource_get_odm_slice_count(otg_master); + h_active = timing->h_addressable + + timing->h_border_left + + timing->h_border_right; + width = h_active / count; + + if (otg_master->stream_res.tg && otg_master->stream) two_pixel_alignment_required = otg_master->stream_res.tg->funcs->is_two_pixels_per_container(timing); if ((width % 2) && two_pixel_alignment_required) |