From 860a024bf4ef43fe787cc5319364054da686d89f Mon Sep 17 00:00:00 2001 From: Banajit Goswami Date: Mon, 10 Apr 2017 19:56:25 -0700 Subject: soc: q6dspv2: apr: fix client registration refcount Audio Packet Router (APR) is used by multiple audio services to communicate between APSS and ADSP. These audio services registers for service level APR communication (port 0xFFFFFFFF), or for session level APR communication (using port 0x101 etc.). The services might choose to call apr_register for any port at random. The expectation is that the refcounting for the number of ports registered with APR for any specific service, is handled irrespective of the order in which registrations are done. The current logic fails to handle the refcounting when apr_register is called for 0xFFFFFFFF before other session based ports. Fix this correctly using the service count (svc_cnt) variable in apr_svc. CRs-fixed: 2022490 Change-Id: I2fcd1269facf24d509db0d90314e0d2545a2ad67 Signed-off-by: Banajit Goswami --- drivers/soc/qcom/qdsp6v2/apr.c | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/drivers/soc/qcom/qdsp6v2/apr.c b/drivers/soc/qcom/qdsp6v2/apr.c index 128ea434dcc8..a275537d4e08 100644 --- a/drivers/soc/qcom/qdsp6v2/apr.c +++ b/drivers/soc/qcom/qdsp6v2/apr.c @@ -514,19 +514,19 @@ struct apr_svc *apr_register(char *dest, char *svc_name, apr_fn svc_fn, mutex_unlock(&svc->m_lock); return NULL; } - if (!svc->port_cnt && !svc->svc_cnt) + if (!svc->svc_cnt) clnt->svc_cnt++; svc->port_cnt++; svc->port_fn[temp_port] = svc_fn; svc->port_priv[temp_port] = priv; + svc->svc_cnt++; } else { if (!svc->fn) { - if (!svc->port_cnt && !svc->svc_cnt) + if (!svc->svc_cnt) clnt->svc_cnt++; svc->fn = svc_fn; - if (svc->port_cnt) - svc->svc_cnt++; svc->priv = priv; + svc->svc_cnt++; } } @@ -745,29 +745,28 @@ int apr_deregister(void *handle) if (!handle) return -EINVAL; + if (!svc->svc_cnt) { + pr_err("%s: svc already deregistered. svc = %pK\n", + __func__, svc); + return -EINVAL; + } + mutex_lock(&svc->m_lock); dest_id = svc->dest_id; client_id = svc->client_id; clnt = &client[dest_id][client_id]; - if (svc->port_cnt > 0 || svc->svc_cnt > 0) { + if (svc->svc_cnt > 0) { if (svc->port_cnt) svc->port_cnt--; - else if (svc->svc_cnt) - svc->svc_cnt--; - if (!svc->port_cnt && !svc->svc_cnt) { + svc->svc_cnt--; + if (!svc->svc_cnt) { client[dest_id][client_id].svc_cnt--; - svc->need_reset = 0x0; - } - } else if (client[dest_id][client_id].svc_cnt > 0) { - client[dest_id][client_id].svc_cnt--; - if (!client[dest_id][client_id].svc_cnt) { - svc->need_reset = 0x0; pr_debug("%s: service is reset %pK\n", __func__, svc); } } - if (!svc->port_cnt && !svc->svc_cnt) { + if (!svc->svc_cnt) { svc->priv = NULL; svc->id = 0; svc->fn = NULL; -- cgit v1.2.3