From 3c2489dfbfd55220f30f710a0408146df3b87e9f Mon Sep 17 00:00:00 2001 From: Xiaoyu Ye Date: Fri, 11 Dec 2020 01:55:31 -0800 Subject: [PATCH] dsp: fix shared buffer format mixer control Due to SVA5 supports multiple sound models in a signle SVA session, shared buffer format mixer control will be called several time to set the afe data format within one session. This behavior can exhaust all available afe data format sessions without freeing them at the end of a SVA session. Fix this issue by using fe_id to find the matching SVA session when set afe data format. Change-Id: I3332b9ff88df2b14eb3e59036164f11ad3342e14 Signed-off-by: Xiaoyu Ye --- dsp/q6lsm.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/dsp/q6lsm.c b/dsp/q6lsm.c index af0fd4326cb4..4dc7e45318a9 100644 --- a/dsp/q6lsm.c +++ b/dsp/q6lsm.c @@ -1252,7 +1252,7 @@ int get_lsm_port(void) */ int q6lsm_set_afe_data_format(uint64_t fe_id, uint16_t afe_data_format) { - int n = 0; + int n = 0, free_session = LSM_INVALID_SESSION_ID; if (0 != afe_data_format && 1 != afe_data_format) goto done; @@ -1261,8 +1261,13 @@ int q6lsm_set_afe_data_format(uint64_t fe_id, uint16_t afe_data_format) afe_data_format ? "unprocessed" : "processed"); for (n = LSM_MIN_SESSION_ID; n <= LSM_MAX_SESSION_ID; n++) { - if (0 == lsm_client_afe_data[n].fe_id) { - lsm_client_afe_data[n].fe_id = fe_id; + /* Save ID of the first available free session */ + if (LSM_INVALID_SESSION_ID == free_session && + 0 == lsm_client_afe_data[n].fe_id) + free_session = n; + + /* Find the matching session with fe_id */ + if (fe_id == lsm_client_afe_data[n].fe_id) { lsm_client_afe_data[n].unprocessed_data = afe_data_format; pr_debug("%s: session ID is %d, fe_id is %d\n", @@ -1270,6 +1275,18 @@ int q6lsm_set_afe_data_format(uint64_t fe_id, uint16_t afe_data_format) return 0; } } + /* + * When no matching session is found, allocate + * a new one if a free session is available. + */ + if (free_session != LSM_INVALID_SESSION_ID) { + lsm_client_afe_data[free_session].fe_id = fe_id; + lsm_client_afe_data[free_session].unprocessed_data = + afe_data_format; + pr_debug("%s: session ID is %d, fe_id is %d\n", + __func__, free_session, fe_id); + return 0; + } pr_err("%s: all lsm sessions are taken\n", __func__); done: