From c2625cbdb17c4938ac22308039212d7ad4ad3cae Mon Sep 17 00:00:00 2001 From: Rander Wang Date: Tue, 13 Nov 2018 15:18:23 +0800 Subject: [PATCH] ASoC: SOF: add spin_lock to protect stream allocation function According to hda framework, stream should be protected by reg_lock Signed-off-by: Rander Wang --- sound/soc/sof/intel/hda-stream.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/sound/soc/sof/intel/hda-stream.c b/sound/soc/sof/intel/hda-stream.c index 880c7425c13172..5d530305eda60f 100644 --- a/sound/soc/sof/intel/hda-stream.c +++ b/sound/soc/sof/intel/hda-stream.c @@ -170,6 +170,8 @@ hda_dsp_stream_get(struct snd_sof_dev *sdev, int direction) struct hdac_ext_stream *stream = NULL; struct hdac_stream *s; + spin_lock_irq(&bus->reg_lock); + /* get an unused stream */ list_for_each_entry(s, &bus->stream_list, list) { if (s->direction == direction && !s->opened) { @@ -179,6 +181,8 @@ hda_dsp_stream_get(struct snd_sof_dev *sdev, int direction) } } + spin_unlock_irq(&bus->reg_lock); + /* stream found ? */ if (!stream) dev_err(sdev->dev, "error: no free %s streams\n", @@ -194,15 +198,20 @@ int hda_dsp_stream_put(struct snd_sof_dev *sdev, int direction, int tag) struct hdac_bus *bus = sof_to_bus(sdev); struct hdac_stream *s; + spin_lock_irq(&bus->reg_lock); + /* find used stream */ list_for_each_entry(s, &bus->stream_list, list) { if (s->direction == direction && s->opened && s->stream_tag == tag) { s->opened = false; + spin_unlock_irq(&bus->reg_lock); return 0; } } + spin_unlock_irq(&bus->reg_lock); + dev_dbg(sdev->dev, "tag %d not opened!\n", tag); return -ENODEV; }