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

drm/amd/display: handle failed allocation during stream construction

[Why]
Failing to allocate a transfer function during stream construction leads
to a null pointer dereference

[How]
Handle the failed allocation by failing the stream construction

Cc: stable@vger.kernel.org
Signed-off-by: Josip Pavic <Josip.Pavic@amd.com>
Reviewed-by: Aric Cyr <Aric.Cyr@amd.com>
Acked-by: Rodrigo Siqueira <Rodrigo.Siqueira@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>

authored by

Josip Pavic and committed by
Alex Deucher
be73e608 b448d30b

+16 -3
+16 -3
drivers/gpu/drm/amd/display/dc/core/dc_stream.c
··· 56 56 } 57 57 } 58 58 59 - static void dc_stream_construct(struct dc_stream_state *stream, 59 + static bool dc_stream_construct(struct dc_stream_state *stream, 60 60 struct dc_sink *dc_sink_data) 61 61 { 62 62 uint32_t i = 0; ··· 118 118 update_stream_signal(stream, dc_sink_data); 119 119 120 120 stream->out_transfer_func = dc_create_transfer_func(); 121 + if (stream->out_transfer_func == NULL) { 122 + dc_sink_release(dc_sink_data); 123 + return false; 124 + } 121 125 stream->out_transfer_func->type = TF_TYPE_BYPASS; 122 126 stream->out_transfer_func->ctx = stream->ctx; 123 127 124 128 stream->stream_id = stream->ctx->dc_stream_id_count; 125 129 stream->ctx->dc_stream_id_count++; 130 + 131 + return true; 126 132 } 127 133 128 134 static void dc_stream_destruct(struct dc_stream_state *stream) ··· 170 164 171 165 stream = kzalloc(sizeof(struct dc_stream_state), GFP_KERNEL); 172 166 if (stream == NULL) 173 - return NULL; 167 + goto alloc_fail; 174 168 175 - dc_stream_construct(stream, sink); 169 + if (dc_stream_construct(stream, sink) == false) 170 + goto construct_fail; 176 171 177 172 kref_init(&stream->refcount); 178 173 179 174 return stream; 175 + 176 + construct_fail: 177 + kfree(stream); 178 + 179 + alloc_fail: 180 + return NULL; 180 181 } 181 182 182 183 struct dc_stream_state *dc_copy_stream(const struct dc_stream_state *stream)