From 849a528506e95209dccab4e1a27674237b7cb978 Mon Sep 17 00:00:00 2001 From: Seppo Ingalsuo Date: Fri, 22 Sep 2017 16:08:44 +0300 Subject: [PATCH] SRC: Add checks for number of channels when initializing from params This patch prevents SRCs init to loop past PLATFORM_MAX_CHANNELS. Signed-off-by: Seppo Ingalsuo --- src/audio/src.c | 5 +++-- src/audio/src_core.h | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/audio/src.c b/src/audio/src.c index 1f84a5aab..203e8025b 100644 --- a/src/audio/src.c +++ b/src/audio/src.c @@ -322,7 +322,7 @@ static int src_params(struct comp_dev *dev) size_t delay_lines_size; uint32_t source_rate, sink_rate; int32_t *buffer_start; - int n = 0, i, err, frames_is_for_source, q; + int n = 0, i, err, frames_is_for_source, nch, q; trace_src("par"); @@ -392,7 +392,8 @@ static int src_params(struct comp_dev *dev) buffer_start = cd->delay_lines + need.scratch; /* Initize SRC for actual sample rate */ - for (i = 0; i < params->channels; i++) { + nch = MIN(params->channels, PLATFORM_MAX_CHANNELS); + for (i = 0; i < nch; i++) { n = src_polyphase_init(&cd->src[i], source_rate, sink_rate, &need, buffer_start); buffer_start += need.single_src; diff --git a/src/audio/src_core.h b/src/audio/src_core.h index 5977421b1..886cc23b0 100644 --- a/src/audio/src_core.h +++ b/src/audio/src_core.h @@ -33,6 +33,7 @@ #define SRC_CORE_H #define MAX(a, b) (((a) > (b)) ? (a) : (b)) +#define MIN(a, b) (((a) < (b)) ? (a) : (b)) struct src_alloc { int fir_s1;