* [PATCH 1/7] ASoC: SOF: Use guard()/scoped_guard() for mutex locks where it makes sense
2026-01-12 10:09 [PATCH 0/7] ASoC: SOF: Use guard()/scoped_guard() for locks when makes sense Peter Ujfalusi
@ 2026-01-12 10:09 ` Peter Ujfalusi
2026-01-12 10:09 ` [PATCH 2/7] ASoC: SOF: Intel: " Peter Ujfalusi
` (6 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Peter Ujfalusi @ 2026-01-12 10:09 UTC (permalink / raw)
To: lgirdwood, broonie
Cc: linux-sound, kai.vehmanen, ranjani.sridharan, yung-chuan.liao,
pierre-louis.bossart, daniel.baluta
Replace the manual mutex lock/unlock pairs with guard()/scoped_guard().
Only code refactoring, and no behavior change.
Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
Reviewed-by: Daniel Baluta <daniel.baluta@nxp.com>
Reviewed-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
---
sound/soc/sof/ipc.c | 5 ++--
sound/soc/sof/ipc3-topology.c | 6 ++---
sound/soc/sof/ipc3.c | 8 ++----
sound/soc/sof/ipc4-mtrace.c | 24 +++++++-----------
sound/soc/sof/ipc4-pcm.c | 3 +--
sound/soc/sof/ipc4-topology.c | 5 +---
sound/soc/sof/ipc4.c | 8 ++----
sound/soc/sof/ops.h | 10 +++-----
sound/soc/sof/sof-audio.c | 46 +++++++++++++----------------------
sound/soc/sof/sof-client.c | 40 +++++++++---------------------
10 files changed, 51 insertions(+), 104 deletions(-)
diff --git a/sound/soc/sof/ipc.c b/sound/soc/sof/ipc.c
index 3fb8d3e9dc6a..3fdeb07bafa3 100644
--- a/sound/soc/sof/ipc.c
+++ b/sound/soc/sof/ipc.c
@@ -225,9 +225,8 @@ void snd_sof_ipc_free(struct snd_sof_dev *sdev)
return;
/* disable sending of ipc's */
- mutex_lock(&ipc->tx_mutex);
- ipc->disable_ipc_tx = true;
- mutex_unlock(&ipc->tx_mutex);
+ scoped_guard(mutex, &ipc->tx_mutex)
+ ipc->disable_ipc_tx = true;
if (ipc->ops->exit)
ipc->ops->exit(sdev);
diff --git a/sound/soc/sof/ipc3-topology.c b/sound/soc/sof/ipc3-topology.c
index f449362a2905..743f42fb26c0 100644
--- a/sound/soc/sof/ipc3-topology.c
+++ b/sound/soc/sof/ipc3-topology.c
@@ -2427,9 +2427,9 @@ static int sof_ipc3_free_widgets_in_list(struct snd_sof_dev *sdev, bool include_
/* Do not free widgets for static pipelines with FW older than SOF2.2 */
if (!verify && !swidget->dynamic_pipeline_widget &&
SOF_FW_VER(v->major, v->minor, v->micro) < SOF_FW_VER(2, 2, 0)) {
- mutex_lock(&swidget->setup_mutex);
- swidget->use_count = 0;
- mutex_unlock(&swidget->setup_mutex);
+ scoped_guard(mutex, &swidget->setup_mutex)
+ swidget->use_count = 0;
+
if (swidget->spipe)
swidget->spipe->complete = 0;
continue;
diff --git a/sound/soc/sof/ipc3.c b/sound/soc/sof/ipc3.c
index 4a194a705ace..85bb22bbe18d 100644
--- a/sound/soc/sof/ipc3.c
+++ b/sound/soc/sof/ipc3.c
@@ -378,7 +378,7 @@ static int sof_ipc3_tx_msg(struct snd_sof_dev *sdev, void *msg_data, size_t msg_
}
/* Serialise IPC TX */
- mutex_lock(&ipc->tx_mutex);
+ guard(mutex)(&ipc->tx_mutex);
ret = ipc3_tx_msg_unlocked(ipc, msg_data, msg_bytes, reply_data, reply_bytes);
@@ -405,8 +405,6 @@ static int sof_ipc3_tx_msg(struct snd_sof_dev *sdev, void *msg_data, size_t msg_
}
}
- mutex_unlock(&ipc->tx_mutex);
-
return ret;
}
@@ -477,7 +475,7 @@ static int sof_ipc3_set_get_data(struct snd_sof_dev *sdev, void *data, size_t da
memcpy(cdata_chunk, cdata, hdr_bytes);
/* Serialise IPC TX */
- mutex_lock(&sdev->ipc->tx_mutex);
+ guard(mutex)(&ipc->tx_mutex);
/* copy the payload data in a loop */
for (i = 0; i < num_msg; i++) {
@@ -511,8 +509,6 @@ static int sof_ipc3_set_get_data(struct snd_sof_dev *sdev, void *data, size_t da
sof_ipc3_dump_payload(sdev, payload, data_bytes - header_bytes);
}
- mutex_unlock(&sdev->ipc->tx_mutex);
-
kfree(cdata_chunk);
return ret;
diff --git a/sound/soc/sof/ipc4-mtrace.c b/sound/soc/sof/ipc4-mtrace.c
index aa5b78604db6..cfd999b42458 100644
--- a/sound/soc/sof/ipc4-mtrace.c
+++ b/sound/soc/sof/ipc4-mtrace.c
@@ -118,22 +118,19 @@ static int sof_ipc4_mtrace_dfs_open(struct inode *inode, struct file *file)
struct sof_mtrace_core_data *core_data = inode->i_private;
int ret;
- mutex_lock(&core_data->buffer_lock);
+ guard(mutex)(&core_data->buffer_lock);
- if (core_data->log_buffer) {
- ret = -EBUSY;
- goto out;
- }
+ if (core_data->log_buffer)
+ return -EBUSY;
ret = debugfs_file_get(file->f_path.dentry);
if (unlikely(ret))
- goto out;
+ return ret;
core_data->log_buffer = kmalloc(SOF_IPC4_DEBUG_SLOT_SIZE, GFP_KERNEL);
if (!core_data->log_buffer) {
debugfs_file_put(file->f_path.dentry);
- ret = -ENOMEM;
- goto out;
+ return -ENOMEM;
}
ret = simple_open(inode, file);
@@ -142,9 +139,6 @@ static int sof_ipc4_mtrace_dfs_open(struct inode *inode, struct file *file)
debugfs_file_put(file->f_path.dentry);
}
-out:
- mutex_unlock(&core_data->buffer_lock);
-
return ret;
}
@@ -281,10 +275,10 @@ static int sof_ipc4_mtrace_dfs_release(struct inode *inode, struct file *file)
debugfs_file_put(file->f_path.dentry);
- mutex_lock(&core_data->buffer_lock);
- kfree(core_data->log_buffer);
- core_data->log_buffer = NULL;
- mutex_unlock(&core_data->buffer_lock);
+ scoped_guard(mutex, &core_data->buffer_lock) {
+ kfree(core_data->log_buffer);
+ core_data->log_buffer = NULL;
+ }
return 0;
}
diff --git a/sound/soc/sof/ipc4-pcm.c b/sound/soc/sof/ipc4-pcm.c
index 6d81969e181c..c3337c3f08c1 100644
--- a/sound/soc/sof/ipc4-pcm.c
+++ b/sound/soc/sof/ipc4-pcm.c
@@ -487,7 +487,7 @@ static int sof_ipc4_trigger_pipelines(struct snd_soc_component *component,
return -ENOMEM;
}
- mutex_lock(&ipc4_data->pipeline_state_mutex);
+ guard(mutex)(&ipc4_data->pipeline_state_mutex);
/*
* IPC4 requires pipelines to be triggered in order starting at the sink and
@@ -580,7 +580,6 @@ static int sof_ipc4_trigger_pipelines(struct snd_soc_component *component,
}
free:
- mutex_unlock(&ipc4_data->pipeline_state_mutex);
kfree(trigger_list);
kfree(pipe_priority);
return ret;
diff --git a/sound/soc/sof/ipc4-topology.c b/sound/soc/sof/ipc4-topology.c
index 479772dc466a..a5a1ef0b96c4 100644
--- a/sound/soc/sof/ipc4-topology.c
+++ b/sound/soc/sof/ipc4-topology.c
@@ -3150,7 +3150,7 @@ static int sof_ipc4_widget_free(struct snd_sof_dev *sdev, struct snd_sof_widget
struct sof_ipc4_fw_data *ipc4_data = sdev->private;
int ret = 0;
- mutex_lock(&ipc4_data->pipeline_state_mutex);
+ guard(mutex)(&ipc4_data->pipeline_state_mutex);
/* freeing a pipeline frees all the widgets associated with it */
if (swidget->id == snd_soc_dapm_scheduler) {
@@ -3161,7 +3161,6 @@ static int sof_ipc4_widget_free(struct snd_sof_dev *sdev, struct snd_sof_widget
if (pipeline->use_chain_dma) {
dev_warn(sdev->dev, "use_chain_dma set for scheduler %s",
swidget->widget->name);
- mutex_unlock(&ipc4_data->pipeline_state_mutex);
return 0;
}
@@ -3189,8 +3188,6 @@ static int sof_ipc4_widget_free(struct snd_sof_dev *sdev, struct snd_sof_widget
ida_free(&fw_module->m_ida, swidget->instance_id);
}
- mutex_unlock(&ipc4_data->pipeline_state_mutex);
-
return ret;
}
diff --git a/sound/soc/sof/ipc4.c b/sound/soc/sof/ipc4.c
index 73d9f2083326..c9c6c0c52c62 100644
--- a/sound/soc/sof/ipc4.c
+++ b/sound/soc/sof/ipc4.c
@@ -412,7 +412,7 @@ static int sof_ipc4_tx_msg(struct snd_sof_dev *sdev, void *msg_data, size_t msg_
}
/* Serialise IPC TX */
- mutex_lock(&ipc->tx_mutex);
+ guard(mutex)(&ipc->tx_mutex);
ret = ipc4_tx_msg_unlocked(ipc, msg_data, msg_bytes, reply_data, reply_bytes);
@@ -429,8 +429,6 @@ static int sof_ipc4_tx_msg(struct snd_sof_dev *sdev, void *msg_data, size_t msg_
sof_ipc4_dump_payload(sdev, msg->data_ptr, msg->data_size);
}
- mutex_unlock(&ipc->tx_mutex);
-
return ret;
}
@@ -506,7 +504,7 @@ static int sof_ipc4_set_get_data(struct snd_sof_dev *sdev, void *data,
}
/* Serialise IPC TX */
- mutex_lock(&sdev->ipc->tx_mutex);
+ guard(mutex)(&sdev->ipc->tx_mutex);
do {
size_t tx_size, rx_size;
@@ -590,8 +588,6 @@ static int sof_ipc4_set_get_data(struct snd_sof_dev *sdev, void *data,
if (sof_debug_check_flag(SOF_DBG_DUMP_IPC_MESSAGE_PAYLOAD))
sof_ipc4_dump_payload(sdev, ipc4_msg->data_ptr, ipc4_msg->data_size);
- mutex_unlock(&sdev->ipc->tx_mutex);
-
kfree(tx_payload_for_get);
return ret;
diff --git a/sound/soc/sof/ops.h b/sound/soc/sof/ops.h
index d73644e85b6e..72af1f4ff620 100644
--- a/sound/soc/sof/ops.h
+++ b/sound/soc/sof/ops.h
@@ -287,16 +287,12 @@ static inline int
snd_sof_dsp_set_power_state(struct snd_sof_dev *sdev,
const struct sof_dsp_power_state *target_state)
{
- int ret = 0;
-
- mutex_lock(&sdev->power_state_access);
+ guard(mutex)(&sdev->power_state_access);
if (sof_ops(sdev)->set_power_state)
- ret = sof_ops(sdev)->set_power_state(sdev, target_state);
-
- mutex_unlock(&sdev->power_state_access);
+ return sof_ops(sdev)->set_power_state(sdev, target_state);
- return ret;
+ return 0;
}
/* debug */
diff --git a/sound/soc/sof/sof-audio.c b/sound/soc/sof/sof-audio.c
index a9664b4cf43f..d55ee7343f8e 100644
--- a/sound/soc/sof/sof-audio.c
+++ b/sound/soc/sof/sof-audio.c
@@ -121,13 +121,8 @@ static int sof_widget_free_unlocked(struct snd_sof_dev *sdev,
int sof_widget_free(struct snd_sof_dev *sdev, struct snd_sof_widget *swidget)
{
- int ret;
-
- mutex_lock(&swidget->setup_mutex);
- ret = sof_widget_free_unlocked(sdev, swidget);
- mutex_unlock(&swidget->setup_mutex);
-
- return ret;
+ guard(mutex)(&swidget->setup_mutex);
+ return sof_widget_free_unlocked(sdev, swidget);
}
EXPORT_SYMBOL(sof_widget_free);
@@ -240,13 +235,8 @@ static int sof_widget_setup_unlocked(struct snd_sof_dev *sdev,
int sof_widget_setup(struct snd_sof_dev *sdev, struct snd_sof_widget *swidget)
{
- int ret;
-
- mutex_lock(&swidget->setup_mutex);
- ret = sof_widget_setup_unlocked(sdev, swidget);
- mutex_unlock(&swidget->setup_mutex);
-
- return ret;
+ guard(mutex)(&swidget->setup_mutex);
+ return sof_widget_setup_unlocked(sdev, swidget);
}
EXPORT_SYMBOL(sof_widget_setup);
@@ -377,24 +367,22 @@ static int sof_setup_pipeline_connections(struct snd_sof_dev *sdev,
else
swidget = sroute->src_widget;
- mutex_lock(&swidget->setup_mutex);
- if (!swidget->use_count) {
- mutex_unlock(&swidget->setup_mutex);
- continue;
- }
+ scoped_guard(mutex, &swidget->setup_mutex) {
+ if (!swidget->use_count)
+ continue;
- if (tplg_ops && tplg_ops->route_setup) {
- /*
- * this route will get freed when either the source widget or the sink
- * widget is freed during hw_free
- */
- ret = tplg_ops->route_setup(sdev, sroute);
- if (!ret)
- sroute->setup = true;
+ if (tplg_ops && tplg_ops->route_setup) {
+ /*
+ * this route will get freed when either the
+ * source widget or the sink widget is freed
+ * during hw_free
+ */
+ ret = tplg_ops->route_setup(sdev, sroute);
+ if (!ret)
+ sroute->setup = true;
+ }
}
- mutex_unlock(&swidget->setup_mutex);
-
if (ret < 0)
return ret;
}
diff --git a/sound/soc/sof/sof-client.c b/sound/soc/sof/sof-client.c
index b0802484a2d3..38f1d7cec470 100644
--- a/sound/soc/sof/sof-client.c
+++ b/sound/soc/sof/sof-client.c
@@ -265,9 +265,8 @@ int sof_client_dev_register(struct snd_sof_dev *sdev, const char *name, u32 id,
}
/* add to list of SOF client devices */
- mutex_lock(&sdev->ipc_client_mutex);
- list_add(¢ry->list, &sdev->ipc_client_list);
- mutex_unlock(&sdev->ipc_client_mutex);
+ scoped_guard(mutex, &sdev->ipc_client_mutex)
+ list_add(¢ry->list, &sdev->ipc_client_list);
return 0;
@@ -285,7 +284,7 @@ void sof_client_dev_unregister(struct snd_sof_dev *sdev, const char *name, u32 i
{
struct sof_client_dev_entry *centry;
- mutex_lock(&sdev->ipc_client_mutex);
+ guard(mutex)(&sdev->ipc_client_mutex);
/*
* sof_client_auxdev_release() will be invoked to free up memory
@@ -301,8 +300,6 @@ void sof_client_dev_unregister(struct snd_sof_dev *sdev, const char *name, u32 i
break;
}
}
-
- mutex_unlock(&sdev->ipc_client_mutex);
}
EXPORT_SYMBOL_NS_GPL(sof_client_dev_unregister, "SND_SOC_SOF_CLIENT");
@@ -400,7 +397,7 @@ int sof_suspend_clients(struct snd_sof_dev *sdev, pm_message_t state)
const struct auxiliary_driver *adrv;
struct sof_client_dev_entry *centry;
- mutex_lock(&sdev->ipc_client_mutex);
+ guard(mutex)(&sdev->ipc_client_mutex);
list_for_each_entry(centry, &sdev->ipc_client_list, list) {
struct sof_client_dev *cdev = ¢ry->client_dev;
@@ -414,8 +411,6 @@ int sof_suspend_clients(struct snd_sof_dev *sdev, pm_message_t state)
adrv->suspend(&cdev->auxdev, state);
}
- mutex_unlock(&sdev->ipc_client_mutex);
-
return 0;
}
EXPORT_SYMBOL_NS_GPL(sof_suspend_clients, "SND_SOC_SOF_CLIENT");
@@ -425,7 +420,7 @@ int sof_resume_clients(struct snd_sof_dev *sdev)
const struct auxiliary_driver *adrv;
struct sof_client_dev_entry *centry;
- mutex_lock(&sdev->ipc_client_mutex);
+ guard(mutex)(&sdev->ipc_client_mutex);
list_for_each_entry(centry, &sdev->ipc_client_list, list) {
struct sof_client_dev *cdev = ¢ry->client_dev;
@@ -439,8 +434,6 @@ int sof_resume_clients(struct snd_sof_dev *sdev)
adrv->resume(&cdev->auxdev);
}
- mutex_unlock(&sdev->ipc_client_mutex);
-
return 0;
}
EXPORT_SYMBOL_NS_GPL(sof_resume_clients, "SND_SOC_SOF_CLIENT");
@@ -532,14 +525,11 @@ void sof_client_ipc_rx_dispatcher(struct snd_sof_dev *sdev, void *msg_buf)
return;
}
- mutex_lock(&sdev->client_event_handler_mutex);
-
+ guard(mutex)(&sdev->client_event_handler_mutex);
list_for_each_entry(event, &sdev->ipc_rx_handler_list, list) {
if (event->ipc_msg_type == msg_type)
event->callback(event->cdev, msg_buf);
}
-
- mutex_unlock(&sdev->client_event_handler_mutex);
}
int sof_client_register_ipc_rx_handler(struct sof_client_dev *cdev,
@@ -573,9 +563,8 @@ int sof_client_register_ipc_rx_handler(struct sof_client_dev *cdev,
event->callback = callback;
/* add to list of SOF client devices */
- mutex_lock(&sdev->client_event_handler_mutex);
+ guard(mutex)(&sdev->client_event_handler_mutex);
list_add(&event->list, &sdev->ipc_rx_handler_list);
- mutex_unlock(&sdev->client_event_handler_mutex);
return 0;
}
@@ -587,7 +576,7 @@ void sof_client_unregister_ipc_rx_handler(struct sof_client_dev *cdev,
struct snd_sof_dev *sdev = sof_client_dev_to_sof_dev(cdev);
struct sof_ipc_event_entry *event;
- mutex_lock(&sdev->client_event_handler_mutex);
+ guard(mutex)(&sdev->ipc_client_mutex);
list_for_each_entry(event, &sdev->ipc_rx_handler_list, list) {
if (event->cdev == cdev && event->ipc_msg_type == ipc_msg_type) {
@@ -596,8 +585,6 @@ void sof_client_unregister_ipc_rx_handler(struct sof_client_dev *cdev,
break;
}
}
-
- mutex_unlock(&sdev->client_event_handler_mutex);
}
EXPORT_SYMBOL_NS_GPL(sof_client_unregister_ipc_rx_handler, "SND_SOC_SOF_CLIENT");
@@ -606,12 +593,10 @@ void sof_client_fw_state_dispatcher(struct snd_sof_dev *sdev)
{
struct sof_state_event_entry *event;
- mutex_lock(&sdev->client_event_handler_mutex);
+ guard(mutex)(&sdev->ipc_client_mutex);
list_for_each_entry(event, &sdev->fw_state_handler_list, list)
event->callback(event->cdev, sdev->fw_state);
-
- mutex_unlock(&sdev->client_event_handler_mutex);
}
int sof_client_register_fw_state_handler(struct sof_client_dev *cdev,
@@ -631,9 +616,8 @@ int sof_client_register_fw_state_handler(struct sof_client_dev *cdev,
event->callback = callback;
/* add to list of SOF client devices */
- mutex_lock(&sdev->client_event_handler_mutex);
+ guard(mutex)(&sdev->client_event_handler_mutex);
list_add(&event->list, &sdev->fw_state_handler_list);
- mutex_unlock(&sdev->client_event_handler_mutex);
return 0;
}
@@ -644,7 +628,7 @@ void sof_client_unregister_fw_state_handler(struct sof_client_dev *cdev)
struct snd_sof_dev *sdev = sof_client_dev_to_sof_dev(cdev);
struct sof_state_event_entry *event;
- mutex_lock(&sdev->client_event_handler_mutex);
+ guard(mutex)(&sdev->ipc_client_mutex);
list_for_each_entry(event, &sdev->fw_state_handler_list, list) {
if (event->cdev == cdev) {
@@ -653,8 +637,6 @@ void sof_client_unregister_fw_state_handler(struct sof_client_dev *cdev)
break;
}
}
-
- mutex_unlock(&sdev->client_event_handler_mutex);
}
EXPORT_SYMBOL_NS_GPL(sof_client_unregister_fw_state_handler, "SND_SOC_SOF_CLIENT");
--
2.52.0
^ permalink raw reply related [flat|nested] 9+ messages in thread* [PATCH 2/7] ASoC: SOF: Intel: Use guard()/scoped_guard() for mutex locks where it makes sense
2026-01-12 10:09 [PATCH 0/7] ASoC: SOF: Use guard()/scoped_guard() for locks when makes sense Peter Ujfalusi
2026-01-12 10:09 ` [PATCH 1/7] ASoC: SOF: Use guard()/scoped_guard() for mutex locks where it " Peter Ujfalusi
@ 2026-01-12 10:09 ` Peter Ujfalusi
2026-01-12 10:10 ` [PATCH 3/7] ASoC: SOF: amd: acp-ipc: Use guard() for spinlock_irq() Peter Ujfalusi
` (5 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Peter Ujfalusi @ 2026-01-12 10:09 UTC (permalink / raw)
To: lgirdwood, broonie
Cc: linux-sound, kai.vehmanen, ranjani.sridharan, yung-chuan.liao,
pierre-louis.bossart, daniel.baluta
Replace the manual mutex lock/unlock pairs with guard()/scoped_guard().
Only code refactoring, and no behavior change.
Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
Reviewed-by: Daniel Baluta <daniel.baluta@nxp.com>
Reviewed-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
---
sound/soc/sof/intel/hda-dai-ops.c | 22 ++++++++++++----------
sound/soc/sof/intel/hda-mlink.c | 29 ++++++++---------------------
2 files changed, 20 insertions(+), 31 deletions(-)
diff --git a/sound/soc/sof/intel/hda-dai-ops.c b/sound/soc/sof/intel/hda-dai-ops.c
index 92681ca7f24d..cdfa3636f70c 100644
--- a/sound/soc/sof/intel/hda-dai-ops.c
+++ b/sound/soc/sof/intel/hda-dai-ops.c
@@ -311,7 +311,7 @@ static int hda_ipc4_pre_trigger(struct snd_sof_dev *sdev, struct snd_soc_dai *cp
if (pipe_widget->instance_id < 0)
return 0;
- mutex_lock(&ipc4_data->pipeline_state_mutex);
+ guard(mutex)(&ipc4_data->pipeline_state_mutex);
switch (cmd) {
case SNDRV_PCM_TRIGGER_START:
@@ -323,16 +323,16 @@ static int hda_ipc4_pre_trigger(struct snd_sof_dev *sdev, struct snd_soc_dai *cp
ret = sof_ipc4_set_pipeline_state(sdev, pipe_widget->instance_id,
SOF_IPC4_PIPE_PAUSED);
if (ret < 0)
- goto out;
+ return ret;
pipeline->state = SOF_IPC4_PIPE_PAUSED;
+
break;
default:
dev_err(sdev->dev, "unknown trigger command %d\n", cmd);
ret = -EINVAL;
}
-out:
- mutex_unlock(&ipc4_data->pipeline_state_mutex);
+
return ret;
}
@@ -388,7 +388,7 @@ static int hda_ipc4_post_trigger(struct snd_sof_dev *sdev, struct snd_soc_dai *c
if (pipe_widget->instance_id < 0)
return 0;
- mutex_lock(&ipc4_data->pipeline_state_mutex);
+ guard(mutex)(&ipc4_data->pipeline_state_mutex);
switch (cmd) {
case SNDRV_PCM_TRIGGER_START:
@@ -396,14 +396,16 @@ static int hda_ipc4_post_trigger(struct snd_sof_dev *sdev, struct snd_soc_dai *c
ret = sof_ipc4_set_pipeline_state(sdev, pipe_widget->instance_id,
SOF_IPC4_PIPE_PAUSED);
if (ret < 0)
- goto out;
+ return ret;
+
pipeline->state = SOF_IPC4_PIPE_PAUSED;
}
ret = sof_ipc4_set_pipeline_state(sdev, pipe_widget->instance_id,
SOF_IPC4_PIPE_RUNNING);
if (ret < 0)
- goto out;
+ return ret;
+
pipeline->state = SOF_IPC4_PIPE_RUNNING;
swidget->spipe->started_count++;
break;
@@ -411,7 +413,8 @@ static int hda_ipc4_post_trigger(struct snd_sof_dev *sdev, struct snd_soc_dai *c
ret = sof_ipc4_set_pipeline_state(sdev, pipe_widget->instance_id,
SOF_IPC4_PIPE_RUNNING);
if (ret < 0)
- goto out;
+ return ret;
+
pipeline->state = SOF_IPC4_PIPE_RUNNING;
break;
case SNDRV_PCM_TRIGGER_SUSPEND:
@@ -429,8 +432,7 @@ static int hda_ipc4_post_trigger(struct snd_sof_dev *sdev, struct snd_soc_dai *c
ret = -EINVAL;
break;
}
-out:
- mutex_unlock(&ipc4_data->pipeline_state_mutex);
+
return ret;
}
diff --git a/sound/soc/sof/intel/hda-mlink.c b/sound/soc/sof/intel/hda-mlink.c
index ce561fe52bd5..6f15213937a3 100644
--- a/sound/soc/sof/intel/hda-mlink.c
+++ b/sound/soc/sof/intel/hda-mlink.c
@@ -524,11 +524,8 @@ void hdac_bus_eml_enable_interrupt(struct hdac_bus *bus, bool alt, int elid, boo
hlink = &h2link->hext_link;
- mutex_lock(&h2link->eml_lock);
-
- hdaml_link_enable_interrupt(hlink->ml_addr + AZX_REG_ML_LCTL, enable);
-
- mutex_unlock(&h2link->eml_lock);
+ scoped_guard(mutex, &h2link->eml_lock)
+ hdaml_link_enable_interrupt(hlink->ml_addr + AZX_REG_ML_LCTL, enable);
}
EXPORT_SYMBOL_NS(hdac_bus_eml_enable_interrupt, "SND_SOC_SOF_HDA_MLINK");
@@ -837,11 +834,8 @@ int hdac_bus_eml_sdw_set_lsdiid(struct hdac_bus *bus, int sublink, int dev_num)
hlink = &h2link->hext_link;
- mutex_lock(&h2link->eml_lock);
-
- hdaml_link_set_lsdiid(hlink->ml_addr + AZX_REG_ML_LSDIID_OFFSET(sublink), dev_num);
-
- mutex_unlock(&h2link->eml_lock);
+ scoped_guard(mutex, &h2link->eml_lock)
+ hdaml_link_set_lsdiid(hlink->ml_addr + AZX_REG_ML_LSDIID_OFFSET(sublink), dev_num);
return 0;
} EXPORT_SYMBOL_NS(hdac_bus_eml_sdw_set_lsdiid, "SND_SOC_SOF_HDA_MLINK");
@@ -875,12 +869,8 @@ int hdac_bus_eml_sdw_map_stream_ch(struct hdac_bus *bus, int sublink, int y,
lchan = 0;
}
- mutex_lock(&h2link->eml_lock);
-
- hdaml_shim_map_stream_ch(pcmsycm, lchan, hchan,
- stream_id, dir);
-
- mutex_unlock(&h2link->eml_lock);
+ scoped_guard(mutex, &h2link->eml_lock)
+ hdaml_shim_map_stream_ch(pcmsycm, lchan, hchan, stream_id, dir);
val = readw(pcmsycm);
@@ -1012,11 +1002,8 @@ int hdac_bus_eml_enable_offload(struct hdac_bus *bus, bool alt, int elid, bool e
hlink = &h2link->hext_link;
- mutex_lock(&h2link->eml_lock);
-
- hdaml_lctl_offload_enable(hlink->ml_addr + AZX_REG_ML_LCTL, enable);
-
- mutex_unlock(&h2link->eml_lock);
+ scoped_guard(mutex, &h2link->eml_lock)
+ hdaml_lctl_offload_enable(hlink->ml_addr + AZX_REG_ML_LCTL, enable);
return 0;
}
--
2.52.0
^ permalink raw reply related [flat|nested] 9+ messages in thread* [PATCH 3/7] ASoC: SOF: amd: acp-ipc: Use guard() for spinlock_irq()
2026-01-12 10:09 [PATCH 0/7] ASoC: SOF: Use guard()/scoped_guard() for locks when makes sense Peter Ujfalusi
2026-01-12 10:09 ` [PATCH 1/7] ASoC: SOF: Use guard()/scoped_guard() for mutex locks where it " Peter Ujfalusi
2026-01-12 10:09 ` [PATCH 2/7] ASoC: SOF: Intel: " Peter Ujfalusi
@ 2026-01-12 10:10 ` Peter Ujfalusi
2026-01-12 10:10 ` [PATCH 4/7] ASoC: SOF: imx: imx-common: Use guard() for spinlock_irqsafe() Peter Ujfalusi
` (4 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Peter Ujfalusi @ 2026-01-12 10:10 UTC (permalink / raw)
To: lgirdwood, broonie
Cc: linux-sound, kai.vehmanen, ranjani.sridharan, yung-chuan.liao,
pierre-louis.bossart, daniel.baluta
Replace the manual spinlock_irq lock/unlock pairs with guard().
Only code refactoring, and no behavior change.
Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
Reviewed-by: Daniel Baluta <daniel.baluta@nxp.com>
Reviewed-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
---
sound/soc/sof/amd/acp-ipc.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/sound/soc/sof/amd/acp-ipc.c b/sound/soc/sof/amd/acp-ipc.c
index 22d4b807e1bb..3cd4674dd800 100644
--- a/sound/soc/sof/amd/acp-ipc.c
+++ b/sound/soc/sof/amd/acp-ipc.c
@@ -190,15 +190,13 @@ irqreturn_t acp_sof_ipc_irq_thread(int irq, void *context)
dsp_ack = snd_sof_dsp_read(sdev, ACP_DSP_BAR, ACP_SCRATCH_REG_0 + dsp_ack_write);
if (dsp_ack) {
if (likely(sdev->fw_state == SOF_FW_BOOT_COMPLETE)) {
- spin_lock_irq(&sdev->ipc_lock);
+ guard(spinlock_irq)(&sdev->ipc_lock);
/* handle immediate reply from DSP core */
acp_dsp_ipc_get_reply(sdev);
snd_sof_ipc_reply(sdev, 0);
/* set the done bit */
acp_dsp_ipc_dsp_done(sdev);
-
- spin_unlock_irq(&sdev->ipc_lock);
} else {
dev_dbg_ratelimited(sdev->dev, "IPC reply before FW_BOOT_COMPLETE: %#x\n",
dsp_ack);
--
2.52.0
^ permalink raw reply related [flat|nested] 9+ messages in thread* [PATCH 4/7] ASoC: SOF: imx: imx-common: Use guard() for spinlock_irqsafe()
2026-01-12 10:09 [PATCH 0/7] ASoC: SOF: Use guard()/scoped_guard() for locks when makes sense Peter Ujfalusi
` (2 preceding siblings ...)
2026-01-12 10:10 ` [PATCH 3/7] ASoC: SOF: amd: acp-ipc: Use guard() for spinlock_irq() Peter Ujfalusi
@ 2026-01-12 10:10 ` Peter Ujfalusi
2026-01-12 10:10 ` [PATCH 5/7] ASoC: SOF: mediatek: mtk-adsp-common: Use guard() for spinlock_irqsave Peter Ujfalusi
` (3 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Peter Ujfalusi @ 2026-01-12 10:10 UTC (permalink / raw)
To: lgirdwood, broonie
Cc: linux-sound, kai.vehmanen, ranjani.sridharan, yung-chuan.liao,
pierre-louis.bossart, daniel.baluta
Replace the manual spinlock_irqsafe lock/unlock pairs with guard().
Only code refactoring, and no behavior change.
Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
Reviewed-by: Daniel Baluta <daniel.baluta@nxp.com>
Reviewed-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
---
sound/soc/sof/imx/imx-common.c | 8 ++------
1 file changed, 2 insertions(+), 6 deletions(-)
diff --git a/sound/soc/sof/imx/imx-common.c b/sound/soc/sof/imx/imx-common.c
index e787d3932fbb..7a03c8cc5dd4 100644
--- a/sound/soc/sof/imx/imx-common.c
+++ b/sound/soc/sof/imx/imx-common.c
@@ -81,14 +81,10 @@ EXPORT_SYMBOL(imx8_dump);
static void imx_handle_reply(struct imx_dsp_ipc *ipc)
{
- struct snd_sof_dev *sdev;
- unsigned long flags;
-
- sdev = imx_dsp_get_data(ipc);
+ struct snd_sof_dev *sdev = imx_dsp_get_data(ipc);
- spin_lock_irqsave(&sdev->ipc_lock, flags);
+ guard(spinlock_irqsave)(&sdev->ipc_lock);
snd_sof_ipc_process_reply(sdev, 0);
- spin_unlock_irqrestore(&sdev->ipc_lock, flags);
}
static void imx_handle_request(struct imx_dsp_ipc *ipc)
--
2.52.0
^ permalink raw reply related [flat|nested] 9+ messages in thread* [PATCH 5/7] ASoC: SOF: mediatek: mtk-adsp-common: Use guard() for spinlock_irqsave
2026-01-12 10:09 [PATCH 0/7] ASoC: SOF: Use guard()/scoped_guard() for locks when makes sense Peter Ujfalusi
` (3 preceding siblings ...)
2026-01-12 10:10 ` [PATCH 4/7] ASoC: SOF: imx: imx-common: Use guard() for spinlock_irqsafe() Peter Ujfalusi
@ 2026-01-12 10:10 ` Peter Ujfalusi
2026-01-12 10:10 ` [PATCH 6/7] ASoC: SOF: Intel: Use guard() for spinlocks where it makes sense Peter Ujfalusi
` (2 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Peter Ujfalusi @ 2026-01-12 10:10 UTC (permalink / raw)
To: lgirdwood, broonie
Cc: linux-sound, kai.vehmanen, ranjani.sridharan, yung-chuan.liao,
pierre-louis.bossart, daniel.baluta
Replace the manual spinlock_irqsave lock/unlock pairs with guard().
Only code refactoring, and no behavior change.
Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
Reviewed-by: Daniel Baluta <daniel.baluta@nxp.com>
Reviewed-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
---
sound/soc/sof/mediatek/mtk-adsp-common.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/sound/soc/sof/mediatek/mtk-adsp-common.c b/sound/soc/sof/mediatek/mtk-adsp-common.c
index 01bbadb160ff..75b4af4b5111 100644
--- a/sound/soc/sof/mediatek/mtk-adsp-common.c
+++ b/sound/soc/sof/mediatek/mtk-adsp-common.c
@@ -107,11 +107,9 @@ EXPORT_SYMBOL(mtk_adsp_send_msg);
void mtk_adsp_handle_reply(struct mtk_adsp_ipc *ipc)
{
struct adsp_priv *priv = mtk_adsp_ipc_get_data(ipc);
- unsigned long flags;
- spin_lock_irqsave(&priv->sdev->ipc_lock, flags);
+ guard(spinlock_irqsave)(&priv->sdev->ipc_lock);
snd_sof_ipc_process_reply(priv->sdev, 0);
- spin_unlock_irqrestore(&priv->sdev->ipc_lock, flags);
}
EXPORT_SYMBOL(mtk_adsp_handle_reply);
--
2.52.0
^ permalink raw reply related [flat|nested] 9+ messages in thread* [PATCH 6/7] ASoC: SOF: Intel: Use guard() for spinlocks where it makes sense
2026-01-12 10:09 [PATCH 0/7] ASoC: SOF: Use guard()/scoped_guard() for locks when makes sense Peter Ujfalusi
` (4 preceding siblings ...)
2026-01-12 10:10 ` [PATCH 5/7] ASoC: SOF: mediatek: mtk-adsp-common: Use guard() for spinlock_irqsave Peter Ujfalusi
@ 2026-01-12 10:10 ` Peter Ujfalusi
2026-01-12 10:10 ` [PATCH 7/7] ASoC: SOF: ipc/ops: Use guard() for spinlocks Peter Ujfalusi
2026-01-13 13:49 ` [PATCH 0/7] ASoC: SOF: Use guard()/scoped_guard() for locks when makes sense Mark Brown
7 siblings, 0 replies; 9+ messages in thread
From: Peter Ujfalusi @ 2026-01-12 10:10 UTC (permalink / raw)
To: lgirdwood, broonie
Cc: linux-sound, kai.vehmanen, ranjani.sridharan, yung-chuan.liao,
pierre-louis.bossart, daniel.baluta
Replace the manual spinlock lock/unlock pairs with guard().
Only code refactoring, and no behavior change.
Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
Reviewed-by: Daniel Baluta <daniel.baluta@nxp.com>
Reviewed-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
---
sound/soc/sof/intel/atom.c | 7 +------
sound/soc/sof/intel/bdw.c | 7 +------
sound/soc/sof/intel/cnl.c | 11 ++---------
sound/soc/sof/intel/hda-dai-ops.c | 3 +--
sound/soc/sof/intel/hda-ipc.c | 11 ++---------
sound/soc/sof/intel/hda-stream.c | 11 ++++-------
sound/soc/sof/intel/mtl.c | 5 +----
7 files changed, 12 insertions(+), 43 deletions(-)
diff --git a/sound/soc/sof/intel/atom.c b/sound/soc/sof/intel/atom.c
index 0d364bcdcfa9..32bf5e5e5978 100644
--- a/sound/soc/sof/intel/atom.c
+++ b/sound/soc/sof/intel/atom.c
@@ -143,9 +143,6 @@ irqreturn_t atom_irq_thread(int irq, void *context)
/* reply message from DSP */
if (ipcx & SHIM_BYT_IPCX_DONE) {
-
- spin_lock_irq(&sdev->ipc_lock);
-
/*
* handle immediate reply from DSP core. If the msg is
* found, set done bit in cmd_done which is called at the
@@ -153,11 +150,9 @@ irqreturn_t atom_irq_thread(int irq, void *context)
* because the done bit can't be set in cmd_done function
* which is triggered by msg
*/
+ guard(spinlock_irq)(&sdev->ipc_lock);
snd_sof_ipc_process_reply(sdev, ipcx);
-
atom_dsp_done(sdev);
-
- spin_unlock_irq(&sdev->ipc_lock);
}
/* new message from DSP */
diff --git a/sound/soc/sof/intel/bdw.c b/sound/soc/sof/intel/bdw.c
index f1287d509835..9534d18be97d 100644
--- a/sound/soc/sof/intel/bdw.c
+++ b/sound/soc/sof/intel/bdw.c
@@ -315,9 +315,6 @@ static irqreturn_t bdw_irq_thread(int irq, void *context)
snd_sof_dsp_update_bits_unlocked(sdev, BDW_DSP_BAR,
SHIM_IMRX, SHIM_IMRX_DONE,
SHIM_IMRX_DONE);
-
- spin_lock_irq(&sdev->ipc_lock);
-
/*
* handle immediate reply from DSP core. If the msg is
* found, set done bit in cmd_done which is called at the
@@ -325,11 +322,9 @@ static irqreturn_t bdw_irq_thread(int irq, void *context)
* because the done bit can't be set in cmd_done function
* which is triggered by msg
*/
+ guard(spinlock_irq)(&sdev->ipc_lock);
snd_sof_ipc_process_reply(sdev, ipcx);
-
bdw_dsp_done(sdev);
-
- spin_unlock_irq(&sdev->ipc_lock);
}
ipcd = snd_sof_dsp_read(sdev, BDW_DSP_BAR, SHIM_IPCD);
diff --git a/sound/soc/sof/intel/cnl.c b/sound/soc/sof/intel/cnl.c
index 0cc5725515e7..69376fb5b20d 100644
--- a/sound/soc/sof/intel/cnl.c
+++ b/sound/soc/sof/intel/cnl.c
@@ -69,13 +69,10 @@ irqreturn_t cnl_ipc4_irq_thread(int irq, void *context)
data->primary = primary;
data->extension = extension;
- spin_lock_irq(&sdev->ipc_lock);
-
+ guard(spinlock_irq)(&sdev->ipc_lock);
snd_sof_ipc_get_reply(sdev);
cnl_ipc_host_done(sdev);
snd_sof_ipc_reply(sdev, data->primary);
-
- spin_unlock_irq(&sdev->ipc_lock);
} else {
dev_dbg_ratelimited(sdev->dev,
"IPC reply before FW_READY: %#x|%#x\n",
@@ -141,15 +138,11 @@ irqreturn_t cnl_ipc_irq_thread(int irq, void *context)
CNL_DSP_REG_HIPCCTL_DONE, 0);
if (likely(sdev->fw_state == SOF_FW_BOOT_COMPLETE)) {
- spin_lock_irq(&sdev->ipc_lock);
-
/* handle immediate reply from DSP core */
+ guard(spinlock_irq)(&sdev->ipc_lock);
hda_dsp_ipc_get_reply(sdev);
snd_sof_ipc_reply(sdev, msg);
-
cnl_ipc_dsp_done(sdev);
-
- spin_unlock_irq(&sdev->ipc_lock);
} else {
dev_dbg_ratelimited(sdev->dev, "IPC reply before FW_READY: %#x\n",
msg);
diff --git a/sound/soc/sof/intel/hda-dai-ops.c b/sound/soc/sof/intel/hda-dai-ops.c
index cdfa3636f70c..b2c559559962 100644
--- a/sound/soc/sof/intel/hda-dai-ops.c
+++ b/sound/soc/sof/intel/hda-dai-ops.c
@@ -58,7 +58,7 @@ hda_link_stream_assign(struct hdac_bus *bus, struct snd_pcm_substream *substream
return NULL;
}
- spin_lock_irq(&bus->reg_lock);
+ guard(spinlock_irq)(&bus->reg_lock);
list_for_each_entry(hstream, &bus->stream_list, list) {
struct hdac_ext_stream *hext_stream =
stream_to_hdac_ext_stream(hstream);
@@ -110,7 +110,6 @@ hda_link_stream_assign(struct hdac_bus *bus, struct snd_pcm_substream *substream
res->link_locked = 1;
res->link_substream = substream;
}
- spin_unlock_irq(&bus->reg_lock);
return res;
}
diff --git a/sound/soc/sof/intel/hda-ipc.c b/sound/soc/sof/intel/hda-ipc.c
index 94425c510861..2aef3954f4f7 100644
--- a/sound/soc/sof/intel/hda-ipc.c
+++ b/sound/soc/sof/intel/hda-ipc.c
@@ -204,13 +204,10 @@ irqreturn_t hda_dsp_ipc4_irq_thread(int irq, void *context)
data->primary = primary;
data->extension = extension;
- spin_lock_irq(&sdev->ipc_lock);
-
+ guard(spinlock_irq)(&sdev->ipc_lock);
snd_sof_ipc_get_reply(sdev);
hda_dsp_ipc_host_done(sdev);
snd_sof_ipc_reply(sdev, data->primary);
-
- spin_unlock_irq(&sdev->ipc_lock);
} else {
dev_dbg_ratelimited(sdev->dev,
"IPC reply before FW_READY: %#x|%#x\n",
@@ -289,16 +286,12 @@ irqreturn_t hda_dsp_ipc_irq_thread(int irq, void *context)
* reply.
*/
if (likely(sdev->fw_state == SOF_FW_BOOT_COMPLETE)) {
- spin_lock_irq(&sdev->ipc_lock);
-
/* handle immediate reply from DSP core */
+ guard(spinlock_irq)(&sdev->ipc_lock);
hda_dsp_ipc_get_reply(sdev);
snd_sof_ipc_reply(sdev, msg);
-
/* set the done bit */
hda_dsp_ipc_dsp_done(sdev);
-
- spin_unlock_irq(&sdev->ipc_lock);
} else {
dev_dbg_ratelimited(sdev->dev, "IPC reply before FW_READY: %#x\n",
msg);
diff --git a/sound/soc/sof/intel/hda-stream.c b/sound/soc/sof/intel/hda-stream.c
index 9c3b3a9aaf83..8fdaf1fdc338 100644
--- a/sound/soc/sof/intel/hda-stream.c
+++ b/sound/soc/sof/intel/hda-stream.c
@@ -724,12 +724,12 @@ int hda_dsp_stream_hw_free(struct snd_sof_dev *sdev,
struct hdac_bus *bus = sof_to_bus(sdev);
u32 mask = BIT(hstream->index);
- spin_lock_irq(&bus->reg_lock);
+ guard(spinlock_irq)(&bus->reg_lock);
+
/* couple host and link DMA if link DMA channel is idle */
if (!hext_stream->link_locked)
snd_sof_dsp_update_bits(sdev, HDA_DSP_PP_BAR,
SOF_HDA_REG_PP_PPCTL, mask, 0);
- spin_unlock_irq(&bus->reg_lock);
}
hda_dsp_stream_spib_config(sdev, hext_stream, HDA_DSP_SPIB_DISABLE, 0);
@@ -747,7 +747,7 @@ bool hda_dsp_check_stream_irq(struct snd_sof_dev *sdev)
u32 status;
/* The function can be called at irq thread, so use spin_lock_irq */
- spin_lock_irq(&bus->reg_lock);
+ guard(spinlock_irq)(&bus->reg_lock);
status = snd_sof_dsp_read(sdev, HDA_DSP_HDA_BAR, SOF_HDA_INTSTS);
@@ -757,8 +757,6 @@ bool hda_dsp_check_stream_irq(struct snd_sof_dev *sdev)
if (status != 0xffffffff)
ret = true;
- spin_unlock_irq(&bus->reg_lock);
-
return ret;
}
EXPORT_SYMBOL_NS(hda_dsp_check_stream_irq, "SND_SOC_SOF_INTEL_HDA_COMMON");
@@ -842,7 +840,7 @@ irqreturn_t hda_dsp_stream_threaded_handler(int irq, void *context)
* unsolicited responses from the codec
*/
for (i = 0, active = true; i < 10 && active; i++) {
- spin_lock_irq(&bus->reg_lock);
+ guard(spinlock_irq)(&bus->reg_lock);
status = snd_sof_dsp_read(sdev, HDA_DSP_HDA_BAR, SOF_HDA_INTSTS);
@@ -853,7 +851,6 @@ irqreturn_t hda_dsp_stream_threaded_handler(int irq, void *context)
if (status & AZX_INT_CTRL_EN) {
active |= hda_codec_check_rirb_status(sdev);
}
- spin_unlock_irq(&bus->reg_lock);
}
return IRQ_HANDLED;
diff --git a/sound/soc/sof/intel/mtl.c b/sound/soc/sof/intel/mtl.c
index 095dcf1a18e4..4ac81537ca05 100644
--- a/sound/soc/sof/intel/mtl.c
+++ b/sound/soc/sof/intel/mtl.c
@@ -596,13 +596,10 @@ static irqreturn_t mtl_ipc_irq_thread(int irq, void *context)
data->primary = primary;
data->extension = extension;
- spin_lock_irq(&sdev->ipc_lock);
-
+ guard(spinlock_irq)(&sdev->ipc_lock);
snd_sof_ipc_get_reply(sdev);
mtl_ipc_host_done(sdev);
snd_sof_ipc_reply(sdev, data->primary);
-
- spin_unlock_irq(&sdev->ipc_lock);
} else {
dev_dbg_ratelimited(sdev->dev,
"IPC reply before FW_READY: %#x|%#x\n",
--
2.52.0
^ permalink raw reply related [flat|nested] 9+ messages in thread* [PATCH 7/7] ASoC: SOF: ipc/ops: Use guard() for spinlocks
2026-01-12 10:09 [PATCH 0/7] ASoC: SOF: Use guard()/scoped_guard() for locks when makes sense Peter Ujfalusi
` (5 preceding siblings ...)
2026-01-12 10:10 ` [PATCH 6/7] ASoC: SOF: Intel: Use guard() for spinlocks where it makes sense Peter Ujfalusi
@ 2026-01-12 10:10 ` Peter Ujfalusi
2026-01-13 13:49 ` [PATCH 0/7] ASoC: SOF: Use guard()/scoped_guard() for locks when makes sense Mark Brown
7 siblings, 0 replies; 9+ messages in thread
From: Peter Ujfalusi @ 2026-01-12 10:10 UTC (permalink / raw)
To: lgirdwood, broonie
Cc: linux-sound, kai.vehmanen, ranjani.sridharan, yung-chuan.liao,
pierre-louis.bossart, daniel.baluta
Replace the manual spinlock lock/unlock pairs with guard().
Only code refactoring, and no behavior change.
Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
Reviewed-by: Daniel Baluta <daniel.baluta@nxp.com>
Reviewed-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
---
sound/soc/sof/ipc.c | 4 +---
sound/soc/sof/ops.c | 34 +++++++---------------------------
2 files changed, 8 insertions(+), 30 deletions(-)
diff --git a/sound/soc/sof/ipc.c b/sound/soc/sof/ipc.c
index 3fdeb07bafa3..e6d8894b8ef6 100644
--- a/sound/soc/sof/ipc.c
+++ b/sound/soc/sof/ipc.c
@@ -47,7 +47,7 @@ int sof_ipc_send_msg(struct snd_sof_dev *sdev, void *msg_data, size_t msg_bytes,
* The spin-lock is needed to protect message objects against other
* atomic contexts.
*/
- spin_lock_irq(&sdev->ipc_lock);
+ guard(spinlock_irq)(&sdev->ipc_lock);
/* initialise the message */
msg = &ipc->msg;
@@ -66,8 +66,6 @@ int sof_ipc_send_msg(struct snd_sof_dev *sdev, void *msg_data, size_t msg_bytes,
if (!ret)
msg->ipc_complete = false;
- spin_unlock_irq(&sdev->ipc_lock);
-
return ret;
}
diff --git a/sound/soc/sof/ops.c b/sound/soc/sof/ops.c
index bd52e7ec6883..74c04dcf4167 100644
--- a/sound/soc/sof/ops.c
+++ b/sound/soc/sof/ops.c
@@ -38,13 +38,8 @@ bool snd_sof_pci_update_bits_unlocked(struct snd_sof_dev *sdev, u32 offset,
bool snd_sof_pci_update_bits(struct snd_sof_dev *sdev, u32 offset,
u32 mask, u32 value)
{
- unsigned long flags;
- bool change;
-
- spin_lock_irqsave(&sdev->hw_lock, flags);
- change = snd_sof_pci_update_bits_unlocked(sdev, offset, mask, value);
- spin_unlock_irqrestore(&sdev->hw_lock, flags);
- return change;
+ guard(spinlock_irqsave)(&sdev->hw_lock);
+ return snd_sof_pci_update_bits_unlocked(sdev, offset, mask, value);
}
EXPORT_SYMBOL(snd_sof_pci_update_bits);
@@ -90,28 +85,16 @@ EXPORT_SYMBOL(snd_sof_dsp_update_bits64_unlocked);
bool snd_sof_dsp_update_bits(struct snd_sof_dev *sdev, u32 bar, u32 offset,
u32 mask, u32 value)
{
- unsigned long flags;
- bool change;
-
- spin_lock_irqsave(&sdev->hw_lock, flags);
- change = snd_sof_dsp_update_bits_unlocked(sdev, bar, offset, mask,
- value);
- spin_unlock_irqrestore(&sdev->hw_lock, flags);
- return change;
+ guard(spinlock_irqsave)(&sdev->hw_lock);
+ return snd_sof_dsp_update_bits_unlocked(sdev, bar, offset, mask, value);
}
EXPORT_SYMBOL(snd_sof_dsp_update_bits);
bool snd_sof_dsp_update_bits64(struct snd_sof_dev *sdev, u32 bar, u32 offset,
u64 mask, u64 value)
{
- unsigned long flags;
- bool change;
-
- spin_lock_irqsave(&sdev->hw_lock, flags);
- change = snd_sof_dsp_update_bits64_unlocked(sdev, bar, offset, mask,
- value);
- spin_unlock_irqrestore(&sdev->hw_lock, flags);
- return change;
+ guard(spinlock_irqsave)(&sdev->hw_lock);
+ return snd_sof_dsp_update_bits64_unlocked(sdev, bar, offset, mask, value);
}
EXPORT_SYMBOL(snd_sof_dsp_update_bits64);
@@ -134,11 +117,8 @@ void snd_sof_dsp_update_bits_forced_unlocked(struct snd_sof_dev *sdev, u32 bar,
void snd_sof_dsp_update_bits_forced(struct snd_sof_dev *sdev, u32 bar,
u32 offset, u32 mask, u32 value)
{
- unsigned long flags;
-
- spin_lock_irqsave(&sdev->hw_lock, flags);
+ guard(spinlock_irqsave)(&sdev->hw_lock);
snd_sof_dsp_update_bits_forced_unlocked(sdev, bar, offset, mask, value);
- spin_unlock_irqrestore(&sdev->hw_lock, flags);
}
EXPORT_SYMBOL(snd_sof_dsp_update_bits_forced);
--
2.52.0
^ permalink raw reply related [flat|nested] 9+ messages in thread* Re: [PATCH 0/7] ASoC: SOF: Use guard()/scoped_guard() for locks when makes sense
2026-01-12 10:09 [PATCH 0/7] ASoC: SOF: Use guard()/scoped_guard() for locks when makes sense Peter Ujfalusi
` (6 preceding siblings ...)
2026-01-12 10:10 ` [PATCH 7/7] ASoC: SOF: ipc/ops: Use guard() for spinlocks Peter Ujfalusi
@ 2026-01-13 13:49 ` Mark Brown
7 siblings, 0 replies; 9+ messages in thread
From: Mark Brown @ 2026-01-13 13:49 UTC (permalink / raw)
To: lgirdwood, Peter Ujfalusi
Cc: linux-sound, kai.vehmanen, ranjani.sridharan, yung-chuan.liao,
pierre-louis.bossart, daniel.baluta
On Mon, 12 Jan 2026 12:09:57 +0200, Peter Ujfalusi wrote:
> Only code refactoring, and no behavior change.
>
> Replace most of the manual *lock/*unlock handling with guard use.
>
> Regards,
> Peter
>
> [...]
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next
Thanks!
[1/7] ASoC: SOF: Use guard()/scoped_guard() for mutex locks where it makes sense
commit: 5c19da34df029fdc29fec1bedf210af7d2c4fccf
[2/7] ASoC: SOF: Intel: Use guard()/scoped_guard() for mutex locks where it makes sense
commit: 599a5b00a1bf2fdc5abb42985eb21c1ce3489416
[3/7] ASoC: SOF: amd: acp-ipc: Use guard() for spinlock_irq()
commit: 58a581c38babe5ae2fa96b9a8387418f3275993e
[4/7] ASoC: SOF: imx: imx-common: Use guard() for spinlock_irqsafe()
commit: aa234886c7263e8c78031a20e33a9725acdbcf5d
[5/7] ASoC: SOF: mediatek: mtk-adsp-common: Use guard() for spinlock_irqsave
commit: 36fabc449a055547960712c164bfa3fe77cf0a88
[6/7] ASoC: SOF: Intel: Use guard() for spinlocks where it makes sense
commit: 294b9e7e8ecafd4dd4b1cc13d7585082451be0e7
[7/7] ASoC: SOF: ipc/ops: Use guard() for spinlocks
commit: 83aee46dc2142eed2dc40b5cef0e9e08e14cac42
All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying
to this mail.
Thanks,
Mark
^ permalink raw reply [flat|nested] 9+ messages in thread