From: phucduc.bui@gmail.com
To: Mark Brown <broonie@kernel.org>,
Liam Girdwood <liam.r.girdwood@linux.intel.com>,
Cezary Rojewski <cezary.rojewski@intel.com>
Cc: Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.com>,
Peter Ujfalusi <peter.ujfalusi@linux.intel.com>,
Bard Liao <yung-chuan.liao@linux.intel.com>,
Kai Vehmanen <kai.vehmanen@linux.intel.com>,
Pierre-Louis Bossart <pierre-louis.bossart@linux.dev>,
linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org,
bui duc phuc <phucduc.bui@gmail.com>
Subject: [PATCH 08/20] ASoC: Intel: avs: ipc: Use guard() for mutex & spin locks
Date: Thu, 11 Jun 2026 18:58:49 +0700 [thread overview]
Message-ID: <20260611115901.80438-9-phucduc.bui@gmail.com> (raw)
In-Reply-To: <20260611115901.80438-1-phucduc.bui@gmail.com>
From: bui duc phuc <phucduc.bui@gmail.com>
Clean up the code using guard() for mutex & spin locks.
Additionally, simplify avs_ipc_wait_busy_completion()
while converting the locking code.
No functional change intended.
Signed-off-by: bui duc phuc <phucduc.bui@gmail.com>
---
sound/soc/intel/avs/ipc.c | 105 ++++++++++++++++++--------------------
1 file changed, 49 insertions(+), 56 deletions(-)
diff --git a/sound/soc/intel/avs/ipc.c b/sound/soc/intel/avs/ipc.c
index c0feb9edd7f6..0dae36c83678 100644
--- a/sound/soc/intel/avs/ipc.c
+++ b/sound/soc/intel/avs/ipc.c
@@ -99,39 +99,39 @@ static void avs_dsp_recovery(struct avs_dev *adev)
unsigned int core_mask;
int ret;
- mutex_lock(&adev->comp_list_mutex);
- /* disconnect all running streams */
- list_for_each_entry(acomp, &adev->comp_list, node) {
- struct snd_soc_pcm_runtime *rtd;
- struct snd_soc_card *card;
-
- card = acomp->base.card;
- if (!card)
- continue;
-
- for_each_card_rtds(card, rtd) {
- struct snd_pcm *pcm;
- int dir;
-
- pcm = rtd->pcm;
- if (!pcm || rtd->dai_link->no_pcm)
+ scoped_guard(mutex, &adev->comp_list_mutex) {
+ /* disconnect all running streams */
+ list_for_each_entry(acomp, &adev->comp_list, node) {
+ struct snd_soc_pcm_runtime *rtd;
+ struct snd_soc_card *card;
+
+ card = acomp->base.card;
+ if (!card)
continue;
- for_each_pcm_streams(dir) {
- struct snd_pcm_substream *substream;
+ for_each_card_rtds(card, rtd) {
+ struct snd_pcm *pcm;
+ int dir;
- substream = pcm->streams[dir].substream;
- if (!substream || !substream->runtime)
+ pcm = rtd->pcm;
+ if (!pcm || rtd->dai_link->no_pcm)
continue;
- /* No need for _irq() as we are in nonatomic context. */
- snd_pcm_stream_lock(substream);
- snd_pcm_stop(substream, SNDRV_PCM_STATE_DISCONNECTED);
- snd_pcm_stream_unlock(substream);
+ for_each_pcm_streams(dir) {
+ struct snd_pcm_substream *substream;
+
+ substream = pcm->streams[dir].substream;
+ if (!substream || !substream->runtime)
+ continue;
+
+ /* No need for _irq() as we are in nonatomic context. */
+ snd_pcm_stream_lock(substream);
+ snd_pcm_stop(substream, SNDRV_PCM_STATE_DISCONNECTED);
+ snd_pcm_stream_unlock(substream);
+ }
}
}
}
- mutex_unlock(&adev->comp_list_mutex);
/* forcibly shutdown all cores */
core_mask = GENMASK(adev->hw_cfg.dsp_cores - 1, 0);
@@ -294,10 +294,10 @@ void avs_dsp_process_response(struct avs_dev *adev, u64 header)
*/
if (avs_msg_is_reply(header)) {
/* Response processing is invoked from IRQ thread. */
- spin_lock_irq(&ipc->rx_lock);
- avs_dsp_receive_rx(adev, header);
- ipc->rx_completed = true;
- spin_unlock_irq(&ipc->rx_lock);
+ scoped_guard(spinlock_irq, &ipc->rx_lock) {
+ avs_dsp_receive_rx(adev, header);
+ ipc->rx_completed = true;
+ }
} else {
avs_dsp_process_notification(adev, header);
}
@@ -338,21 +338,18 @@ static int avs_ipc_wait_busy_completion(struct avs_ipc *ipc, int timeout)
}
/* Ongoing notification's bottom-half may cause early wakeup */
- spin_lock(&ipc->rx_lock);
- if (!ipc->rx_completed) {
- if (repeats_left) {
+ scoped_guard(spinlock, &ipc->rx_lock) {
+ if (!ipc->rx_completed) {
+ if (!repeats_left)
+ return -ETIMEDOUT;
+
/* Reply delayed due to notification. */
repeats_left--;
reinit_completion(&ipc->busy_completion);
- spin_unlock(&ipc->rx_lock);
goto again;
}
-
- spin_unlock(&ipc->rx_lock);
- return -ETIMEDOUT;
}
- spin_unlock(&ipc->rx_lock);
return 0;
}
@@ -397,12 +394,12 @@ static int avs_dsp_do_send_msg(struct avs_dev *adev, struct avs_ipc_msg *request
if (!ipc->ready)
return -EPERM;
- mutex_lock(&ipc->msg_mutex);
+ guard(mutex)(&ipc->msg_mutex);
- spin_lock(&ipc->rx_lock);
- avs_ipc_msg_init(ipc, reply);
- avs_dsp_send_tx(adev, request, true);
- spin_unlock(&ipc->rx_lock);
+ scoped_guard(spinlock, &ipc->rx_lock) {
+ avs_ipc_msg_init(ipc, reply);
+ avs_dsp_send_tx(adev, request, true);
+ }
ret = avs_ipc_wait_busy_completion(ipc, timeout);
if (ret) {
@@ -412,7 +409,7 @@ static int avs_dsp_do_send_msg(struct avs_dev *adev, struct avs_ipc_msg *request
/* Same treatment as on exception, just stack_dump=0. */
avs_dsp_exception_caught(adev, &msg);
}
- goto exit;
+ return ret;
}
ret = ipc->rx.rsp.status;
@@ -436,8 +433,6 @@ static int avs_dsp_do_send_msg(struct avs_dev *adev, struct avs_ipc_msg *request
memcpy(reply->data, ipc->rx.data, reply->size);
}
-exit:
- mutex_unlock(&ipc->msg_mutex);
return ret;
}
@@ -501,16 +496,16 @@ static int avs_dsp_do_send_rom_msg(struct avs_dev *adev, struct avs_ipc_msg *req
struct avs_ipc *ipc = adev->ipc;
int ret;
- mutex_lock(&ipc->msg_mutex);
+ guard(mutex)(&ipc->msg_mutex);
- spin_lock(&ipc->rx_lock);
- avs_ipc_msg_init(ipc, NULL);
- /*
- * with hw still stalled, memory windows may not be
- * configured properly so avoid accessing SRAM
- */
- avs_dsp_send_tx(adev, request, false);
- spin_unlock(&ipc->rx_lock);
+ scoped_guard(spinlock, &ipc->rx_lock) {
+ avs_ipc_msg_init(ipc, NULL);
+ /*
+ * with hw still stalled, memory windows may not be
+ * configured properly so avoid accessing SRAM
+ */
+ avs_dsp_send_tx(adev, request, false);
+ }
/* ROM messages must be sent before main core is unstalled */
ret = avs_dsp_op(adev, stall, AVS_MAIN_CORE_MASK, false);
@@ -522,8 +517,6 @@ static int avs_dsp_do_send_rom_msg(struct avs_dev *adev, struct avs_ipc_msg *req
dev_err(adev->dev, "%s (0x%08x 0x%08x) failed: %d\n",
name, request->glb.primary, request->glb.ext.val, ret);
- mutex_unlock(&ipc->msg_mutex);
-
return ret;
}
--
2.43.0
next prev parent reply other threads:[~2026-06-11 11:59 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-11 11:58 [PATCH 00/20] ASoC: Intel: Use guard() for mutex & spin locks phucduc.bui
2026-06-11 11:58 ` [PATCH 01/20] ASoC: Intel: catpt: ipc: " phucduc.bui
2026-06-11 18:44 ` Cezary Rojewski
2026-06-12 4:05 ` Bui Duc Phuc
2026-06-11 11:58 ` [PATCH 02/20] ASoC: Intel: catpt: dsp: Use guard() for mutex locks phucduc.bui
2026-06-11 18:39 ` Cezary Rojewski
2026-06-11 11:58 ` [PATCH 03/20] ASoC: Intel: avs: utils: " phucduc.bui
2026-06-11 11:58 ` [PATCH 04/20] ASoC: Intel: avs: probes: Use guard() for spin locks phucduc.bui
2026-06-11 19:34 ` Cezary Rojewski
2026-06-12 4:48 ` Bui Duc Phuc
2026-06-11 11:58 ` [PATCH 05/20] ASoC: Intel: avs: pcm: Use guard() for mutex & " phucduc.bui
2026-06-11 11:58 ` [PATCH 06/20] ASoC: Intel: avs: path: " phucduc.bui
2026-06-11 11:58 ` [PATCH 07/20] ASoC: Intel: avs: loader: Use guard() for mutex locks phucduc.bui
2026-06-11 11:58 ` phucduc.bui [this message]
2026-06-11 11:58 ` [PATCH 09/20] ASoC: Intel: avs: icl: Use guard() for spin locks phucduc.bui
2026-06-11 11:58 ` [PATCH 10/20] ASoC: Intel: avs: debugfs: " phucduc.bui
2026-06-11 11:58 ` [PATCH 11/20] ASoC: Intel: avs: debug: " phucduc.bui
2026-06-11 11:58 ` [PATCH 12/20] ASoC: Intel: avs: core: Use guard() for mutex & " phucduc.bui
2026-06-11 11:58 ` [PATCH 13/20] ASoC: Intel: avs: control: Use guard() for " phucduc.bui
2026-06-11 11:58 ` [PATCH 14/20] ASoC: Intel: avs: apl: " phucduc.bui
2026-06-11 11:58 ` [PATCH 15/20] ASoC: Intel: atom: sst_stream: Use guard() for mutex locks phucduc.bui
2026-06-11 11:58 ` [PATCH 16/20] ASoC: Intel: atom: sst_pvt: Use guard() for mutex & spin locks phucduc.bui
2026-06-11 11:58 ` [PATCH 17/20] ASoC: Intel: atom: sst: Use guard() for " phucduc.bui
2026-06-11 11:58 ` [PATCH 18/20] ASoC: Intel: atom: sst-atom-controls: Use guard() for mutex locks phucduc.bui
2026-06-11 11:59 ` [PATCH 19/20] ASoC: Intel: atom: sst-mfld-platform-pcm: Use guard() for mutex & spin locks phucduc.bui
2026-06-11 11:59 ` [PATCH 20/20] ASoC: Intel: atom: sst_ipc: Use guard() for " phucduc.bui
2026-06-11 19:04 ` [PATCH 00/20] ASoC: Intel: Use guard() for mutex & " Cezary Rojewski
2026-06-12 3:45 ` Bui Duc Phuc
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260611115901.80438-9-phucduc.bui@gmail.com \
--to=phucduc.bui@gmail.com \
--cc=broonie@kernel.org \
--cc=cezary.rojewski@intel.com \
--cc=kai.vehmanen@linux.intel.com \
--cc=liam.r.girdwood@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=perex@perex.cz \
--cc=peter.ujfalusi@linux.intel.com \
--cc=pierre-louis.bossart@linux.dev \
--cc=tiwai@suse.com \
--cc=yung-chuan.liao@linux.intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.