From ae92afd2500e7d14506326c06112648bfd9309e3 Mon Sep 17 00:00:00 2001 From: Masayuki Ishikawa Date: Tue, 16 Jun 2020 12:24:40 +0900 Subject: [PATCH] drivers: audio: Fix cxd56_stop in cxd56.c In the previous implementation, cxd56_stop() checked the internal state before sending AUDIO_MSG_STOP to the message queue. However, if the worker thread took time to turn on AMP, cxd560_stop() was not able to send the message and caused a deadlock. This commit fixes this issue by always sending AUDIO_MSG_STOP regardless of the internal state. Signed-off-by: Masayuki Ishikawa --- drivers/audio/cxd56.c | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/drivers/audio/cxd56.c b/drivers/audio/cxd56.c index 6a3da215fa..866fab9a9c 100644 --- a/drivers/audio/cxd56.c +++ b/drivers/audio/cxd56.c @@ -2899,32 +2899,28 @@ static int cxd56_stop(FAR struct audio_lowerhalf_s *lower, FAR void *session) static int cxd56_stop(FAR struct audio_lowerhalf_s *lower) #endif { + int ret; + FAR void *value; + struct audio_msg_s msg; FAR struct cxd56_dev_s *priv = (FAR struct cxd56_dev_s *)lower; audinfo("cxd56_stop\n"); - if (priv->state != CXD56_DEV_STATE_STOPPED) + msg.msg_id = AUDIO_MSG_STOP; + msg.u.data = 0; + ret = nxmq_send(priv->mq, (FAR const char *)&msg, + sizeof(msg), CONFIG_CXD56_MSG_PRIO); + if (ret != OK) { - int ret; - FAR void *value; - struct audio_msg_s msg; - - msg.msg_id = AUDIO_MSG_STOP; - msg.u.data = 0; - ret = nxmq_send(priv->mq, (FAR const char *)&msg, - sizeof(msg), CONFIG_CXD56_MSG_PRIO); - if (ret != OK) - { - auderr("ERROR: nxmq_send stop message failed (%d)\n", ret); - return ret; - } - - /* Join the worker thread */ - - pthread_join(priv->threadid, &value); - priv->threadid = 0; + auderr("ERROR: nxmq_send stop message failed (%d)\n", ret); + return ret; } + /* Join the worker thread */ + + pthread_join(priv->threadid, &value); + priv->threadid = 0; + return OK; } #endif /* CONFIG_AUDIO_EXCLUDE_STOP */