Skip to content

Commit

Permalink
buffer: init channels to 2
Browse files Browse the repository at this point in the history
On initialization we use rzalloc which 0s out all fields. We later call
audio_stream_recalc_align which uses the frame_bytes to align the buffer.
This is problematic as clz() is passed the size of the frame size which
is 0 since channel is 0 and passing 0 to clz is undefined behaviour.

Signed-off-by: Curtis Malainey <cujomalainey@chromium.org>
  • Loading branch information
cujomalainey authored and lgirdwood committed Oct 1, 2024
1 parent 66bb497 commit 31e22e6
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/audio/buffers/comp_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ static struct comp_buffer *buffer_alloc_struct(void *stream_addr, size_t size, u
}

buffer->caps = caps;
/* Force channels to 2 for init to prevent bad call to clz in buffer_init_stream */
buffer->stream.runtime_stream_params.channels = 2;

audio_buffer_init(&buffer->audio_buffer, BUFFER_TYPE_LEGACY_BUFFER, is_shared,
&comp_buffer_source_ops, &comp_buffer_sink_ops, &audio_buffer_ops,
Expand Down

0 comments on commit 31e22e6

Please sign in to comment.