Unverified Commit 599a5b00 authored by Peter Ujfalusi's avatar Peter Ujfalusi Committed by Mark Brown
Browse files

ASoC: SOF: Intel: Use guard()/scoped_guard() for mutex locks where it makes sense



Replace the manual mutex lock/unlock pairs with guard()/scoped_guard().

Only code refactoring, and no behavior change.

Signed-off-by: default avatarPeter Ujfalusi <peter.ujfalusi@linux.intel.com>
Reviewed-by: default avatarDaniel Baluta <daniel.baluta@nxp.com>
Reviewed-by: default avatarRanjani Sridharan <ranjani.sridharan@linux.intel.com>
Link: https://patch.msgid.link/20260112101004.7648-3-peter.ujfalusi@linux.intel.com


Signed-off-by: default avatarMark Brown <broonie@kernel.org>
parent 5c19da34
Loading
Loading
Loading
Loading
+12 −10
Original line number Diff line number Diff line
@@ -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;
}

+8 −21
Original line number Diff line number Diff line
@@ -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);

	scoped_guard(mutex, &h2link->eml_lock)
		hdaml_link_enable_interrupt(hlink->ml_addr + AZX_REG_ML_LCTL, enable);

	mutex_unlock(&h2link->eml_lock);
}
EXPORT_SYMBOL_NS(hdac_bus_eml_enable_interrupt, "SND_SOC_SOF_HDA_MLINK");

@@ -837,12 +834,9 @@ 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);

	scoped_guard(mutex, &h2link->eml_lock)
		hdaml_link_set_lsdiid(hlink->ml_addr + AZX_REG_ML_LSDIID_OFFSET(sublink), dev_num);

	mutex_unlock(&h2link->eml_lock);

	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,12 +1002,9 @@ 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);

	scoped_guard(mutex, &h2link->eml_lock)
		hdaml_lctl_offload_enable(hlink->ml_addr + AZX_REG_ML_LCTL, enable);

	mutex_unlock(&h2link->eml_lock);

	return 0;
}
EXPORT_SYMBOL_NS(hdac_bus_eml_enable_offload, "SND_SOC_SOF_HDA_MLINK");