alsa-devel.alsa-project.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ASoC: SOF: add mutex to protect the dsp_power_state access
@ 2021-01-05 15:56 Kai Vehmanen
  2021-01-12 16:42 ` Mark Brown
  0 siblings, 1 reply; 2+ messages in thread
From: Kai Vehmanen @ 2021-01-05 15:56 UTC (permalink / raw)
  To: alsa-devel, broonie
  Cc: Guennadi Liakhovetski, kai.vehmanen, Keyon Jie, lgirdwood,
	pierre-louis.bossart, ranjani.sridharan, daniel.baluta,
	Bard Liao

From: Keyon Jie <yang.jie@linux.intel.com>

There could be more than one thread read/write the dsp_power_state
simultaneously (e.g. hda_dsp_d0i3_work and sof_ipc_tx_message), add a
mutex power_state_access to make sure the access to it is mutually
exclusive.

Signed-off-by: Keyon Jie <yang.jie@linux.intel.com>
Reviewed-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Reviewed-by: Bard Liao <bard.liao@intel.com>
Reviewed-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
---
 sound/soc/sof/core.c     |  1 +
 sound/soc/sof/ops.h      | 11 ++++++++---
 sound/soc/sof/sof-priv.h |  2 ++
 3 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/sound/soc/sof/core.c b/sound/soc/sof/core.c
index adc7c37145d6..2b85ef5d6092 100644
--- a/sound/soc/sof/core.c
+++ b/sound/soc/sof/core.c
@@ -316,6 +316,7 @@ int snd_sof_device_probe(struct device *dev, struct snd_sof_pdata *plat_data)
 	INIT_LIST_HEAD(&sdev->route_list);
 	spin_lock_init(&sdev->ipc_lock);
 	spin_lock_init(&sdev->hw_lock);
+	mutex_init(&sdev->power_state_access);
 
 	if (IS_ENABLED(CONFIG_SND_SOC_SOF_PROBE_WORK_QUEUE))
 		INIT_WORK(&sdev->probe_work, sof_probe_work);
diff --git a/sound/soc/sof/ops.h b/sound/soc/sof/ops.h
index 95e748b36903..4c1f9daaa6e8 100644
--- a/sound/soc/sof/ops.h
+++ b/sound/soc/sof/ops.h
@@ -208,11 +208,16 @@ 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);
+
 	if (sof_ops(sdev)->set_power_state)
-		return sof_ops(sdev)->set_power_state(sdev, target_state);
+		ret = sof_ops(sdev)->set_power_state(sdev, target_state);
 
-	/* D0 substate is not supported, do nothing here. */
-	return 0;
+	mutex_unlock(&sdev->power_state_access);
+
+	return ret;
 }
 
 /* debug */
diff --git a/sound/soc/sof/sof-priv.h b/sound/soc/sof/sof-priv.h
index 68da8f797403..28d19fa30614 100644
--- a/sound/soc/sof/sof-priv.h
+++ b/sound/soc/sof/sof-priv.h
@@ -375,6 +375,8 @@ struct snd_sof_dev {
 
 	/* current DSP power state */
 	struct sof_dsp_power_state dsp_power_state;
+	/* mutex to protect the dsp_power_state access */
+	struct mutex power_state_access;
 
 	/* Intended power target of system suspend */
 	enum sof_system_suspend_state system_suspend_target;
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] ASoC: SOF: add mutex to protect the dsp_power_state access
  2021-01-05 15:56 [PATCH] ASoC: SOF: add mutex to protect the dsp_power_state access Kai Vehmanen
@ 2021-01-12 16:42 ` Mark Brown
  0 siblings, 0 replies; 2+ messages in thread
From: Mark Brown @ 2021-01-12 16:42 UTC (permalink / raw)
  To: Kai Vehmanen, alsa-devel
  Cc: Guennadi Liakhovetski, Keyon Jie, lgirdwood,
	pierre-louis.bossart, ranjani.sridharan, daniel.baluta,
	Bard Liao

On Tue, 5 Jan 2021 17:56:40 +0200, Kai Vehmanen wrote:
> There could be more than one thread read/write the dsp_power_state
> simultaneously (e.g. hda_dsp_d0i3_work and sof_ipc_tx_message), add a
> mutex power_state_access to make sure the access to it is mutually
> exclusive.

Applied to

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next

Thanks!

[1/1] ASoC: SOF: add mutex to protect the dsp_power_state access
      commit: 8b66d7c58c11cf3b1a1cea738582367a96cdaaf8

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] 2+ messages in thread

end of thread, other threads:[~2021-01-12 16:43 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-05 15:56 [PATCH] ASoC: SOF: add mutex to protect the dsp_power_state access Kai Vehmanen
2021-01-12 16:42 ` Mark Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).