[Sound-open-firmware] [PATCH 1/4] SRC: Add checks for number of channels when initializing from params

Seppo Ingalsuo seppo.ingalsuo at linux.intel.com
Fri Sep 22 15:08:44 CEST 2017


This patch prevents SRCs init to loop past PLATFORM_MAX_CHANNELS.

Signed-off-by: Seppo Ingalsuo <seppo.ingalsuo at linux.intel.com>
---
 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 1f84a5a..203e802 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 5977421..886cc23 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;
-- 
2.11.0



More information about the Sound-open-firmware mailing list