Commit
55a67aa89342545b89f469dea6f29bfb6fac6f3d
drm/amd/display: Fix NULL sink dereference in USB4 bandwidth functions
allocate_usb4_bandwidth_for_stream() and allocate_usb4_bandwidth() both
use ASSERT(stream->sink) before dereferencing stream->sink->link. ASSERT
is compiled out in production builds, so a NULL stream->sink causes a
NULL pointer dereference.
link_set_dpms_off() already guards two earlier accesses to stream->sink
with explicit NULL checks, confirming that stream->sink can legitimately
be NULL. The subsequent call to deallocate_usb4_bandwidth() had no
equivalent guard.
Replace the ASSERT() calls with proper NULL checks that return false
early, and add a matching stream->sink guard at the call site in
link_set_dpms_off() consistent with the surrounding pattern.
v2: Keep the existing ASSERT() calls for diagnostics (to report
unexpected NULL sink), and add explicit NULL checks that return false
before dereferencing stream->sink. Also add a matching stream->sink
guard at the deallocation call site in link_set_dpms_off(). (Alex)
Fixes: 8fa813b7fd1e ("drm/amd/display: Remove sink usage from DPMS")
Reported-by: Dan Carpenter <error27@gmail.com>
Cc: Nicholas Kazlauskas <nicholas.kazlauskas@amd.com>
Cc: Dominik Kaszewski <dominik.kaszewski@amd.com>
Cc: George Zhang <george.zhang@amd.com>
Cc: Aurabindo Pillai <aurabindo.pillai@amd.com>
Cc: Roman Li <Roman.Li@amd.com>
Cc: Ivan Lipski <ivan.lipski@amd.com>
Cc: Dan Wheeler <daniel.wheeler@amd.com>
Cc: Alex Hung <alex.hung@amd.com>
Cc: Tom Chung <chiahsuan.chung@amd.com>
Signed-off-by: Srinivasan Shanmugam <srinivasan.shanmugam@amd.com>
Tested-by: Dan Wheeler <daniel.wheeler@amd.com>
Reviewed-by: Roman Li <roman.li@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
(cherry picked from commit 98029a0ce61feb52c563f65349dd9b25f672e355)
Cc: stable@vger.kernel.org
Srinivasan Shanmugam <srinivasan.shanmugam@amd.com> · 2026-09-17 06:14 UTC · committed by Alex Deucher
1 file changed,
+14
−4
modified drivers/gpu/drm/amd/display/dc/link/link_dpms.c
| @@ -2306,9 +2306,14 @@ static bool allocate_usb4_bandwidth_for_stream(struct dc_stream_state *stream, i | |||
| 2306 | 2306 | { | |
| 2307 | 2307 | ASSERT(stream->sink); | |
| 2308 | 2308 | ||
| 2309 | - | struct dc_link *link = stream->sink->link; | |
| 2309 | + | struct dc_link *link; | |
| 2310 | 2310 | int req_bw = stream_bw; | |
| 2311 | 2311 | ||
| 2312 | + | if (!stream->sink) | |
| 2313 | + | return false; | |
| 2314 | + | ||
| 2315 | + | link = stream->sink->link; | |
| 2316 | + | ||
| 2312 | 2317 | DC_LOGGER_INIT(link->ctx->logger); | |
| 2313 | 2318 | ||
| 2314 | 2319 | if (!link->dpia_bw_alloc_config.bw_alloc_enabled) | |
| @@ -2355,9 +2360,13 @@ static bool allocate_usb4_bandwidth(struct dc_stream_state *stream) | |||
| 2355 | 2360 | ASSERT(stream->sink); | |
| 2356 | 2361 | ||
| 2357 | 2362 | bool ret; | |
| 2363 | + | int bw; | |
| 2358 | 2364 | ||
| 2359 | - | int bw = dc_bandwidth_in_kbps_from_timing(&stream->timing, | |
| 2360 | - | dc_link_get_highest_encoding_format(stream->sink->link)); | |
| 2365 | + | if (!stream->sink) | |
| 2366 | + | return false; | |
| 2367 | + | ||
| 2368 | + | bw = dc_bandwidth_in_kbps_from_timing(&stream->timing, | |
| 2369 | + | dc_link_get_highest_encoding_format(stream->sink->link)); | |
| 2361 | 2370 | ||
| 2362 | 2371 | ret = allocate_usb4_bandwidth_for_stream(stream, bw); | |
| 2363 | 2372 | ||
| @@ -2419,7 +2428,8 @@ enum dc_status link_set_dpms_off(struct pipe_ctx *pipe_ctx) | |||
| 2419 | 2428 | update_psp_stream_config(pipe_ctx, true); | |
| 2420 | 2429 | dc->hwss.blank_stream(pipe_ctx); | |
| 2421 | 2430 | ||
| 2422 | - | if (pipe_ctx->link_config.dp_tunnel_settings.should_use_dp_bw_allocation) | |
| 2431 | + | if (pipe_ctx->link_config.dp_tunnel_settings.should_use_dp_bw_allocation && | |
| 2432 | + | stream->sink) | |
| 2423 | 2433 | deallocate_usb4_bandwidth(stream); | |
| 2424 | 2434 | ||
| 2425 | 2435 | if (stream->signal == SIGNAL_TYPE_DISPLAY_PORT_MST) | |