]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
ASoC: SOF: Intel: Use guard()/scoped_guard() for mutex locks where it makes sense
authorPeter Ujfalusi <peter.ujfalusi@linux.intel.com>
Mon, 12 Jan 2026 10:09:59 +0000 (12:09 +0200)
committerMark Brown <broonie@kernel.org>
Mon, 12 Jan 2026 11:21:24 +0000 (11:21 +0000)
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>
Link: https://patch.msgid.link/20260112101004.7648-3-peter.ujfalusi@linux.intel.com
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/sof/intel/hda-dai-ops.c
sound/soc/sof/intel/hda-mlink.c

index 92681ca7f24def1307f9a3b7d6e1fc009e566953..cdfa3636f70cb17921aa8dbe0c20245575836568 100644 (file)
@@ -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;
 }
 
index ce561fe52bd5d466c00f71d89c90272cdff55488..6f15213937a3a3df1d26820fdd39f734cf239d7a 100644 (file)
@@ -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;
 }