Skip to content

Commit be73e60

Browse files
Josip Pavicalexdeucher
authored andcommitted
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: [email protected] Signed-off-by: Josip Pavic <[email protected]> Reviewed-by: Aric Cyr <[email protected]> Acked-by: Rodrigo Siqueira <[email protected]> Signed-off-by: Alex Deucher <[email protected]>
1 parent b448d30 commit be73e60

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

drivers/gpu/drm/amd/display/dc/core/dc_stream.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ void update_stream_signal(struct dc_stream_state *stream, struct dc_sink *sink)
5656
}
5757
}
5858

59-
static void dc_stream_construct(struct dc_stream_state *stream,
59+
static bool dc_stream_construct(struct dc_stream_state *stream,
6060
struct dc_sink *dc_sink_data)
6161
{
6262
uint32_t i = 0;
@@ -118,11 +118,17 @@ static void dc_stream_construct(struct dc_stream_state *stream,
118118
update_stream_signal(stream, dc_sink_data);
119119

120120
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+
}
121125
stream->out_transfer_func->type = TF_TYPE_BYPASS;
122126
stream->out_transfer_func->ctx = stream->ctx;
123127

124128
stream->stream_id = stream->ctx->dc_stream_id_count;
125129
stream->ctx->dc_stream_id_count++;
130+
131+
return true;
126132
}
127133

128134
static void dc_stream_destruct(struct dc_stream_state *stream)
@@ -164,13 +170,20 @@ struct dc_stream_state *dc_create_stream_for_sink(
164170

165171
stream = kzalloc(sizeof(struct dc_stream_state), GFP_KERNEL);
166172
if (stream == NULL)
167-
return NULL;
173+
goto alloc_fail;
168174

169-
dc_stream_construct(stream, sink);
175+
if (dc_stream_construct(stream, sink) == false)
176+
goto construct_fail;
170177

171178
kref_init(&stream->refcount);
172179

173180
return stream;
181+
182+
construct_fail:
183+
kfree(stream);
184+
185+
alloc_fail:
186+
return NULL;
174187
}
175188

176189
struct dc_stream_state *dc_copy_stream(const struct dc_stream_state *stream)

0 commit comments

Comments
 (0)