From: Jerome Brunet <jbrunet@baylibre.com>
To: Mark Brown <broonie@kernel.org>, Liam Girdwood <lgirdwood@gmail.com>
Cc: Jerome Brunet <jbrunet@baylibre.com>,
alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org,
Russell King <rmk+kernel@armlinux.org.uk>
Subject: [PATCH 2/2] ASoC: hdmi-codec: re-introduce mutex locking again
Date: Wed, 23 Oct 2019 18:12:03 +0200 [thread overview]
Message-ID: <20191023161203.28955-3-jbrunet@baylibre.com> (raw)
In-Reply-To: <20191023161203.28955-1-jbrunet@baylibre.com>
The dai codec needs to ensure that on one dai is used at any time.
This is currently protected by bit atomic operation. With this change,
it done with a mutex instead.
Suggested-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Jerome Brunet <jbrunet@baylibre.com>
---
sound/soc/codecs/hdmi-codec.c | 23 ++++++++++++++++-------
1 file changed, 16 insertions(+), 7 deletions(-)
diff --git a/sound/soc/codecs/hdmi-codec.c b/sound/soc/codecs/hdmi-codec.c
index f8b5b960e597..56f6373d7927 100644
--- a/sound/soc/codecs/hdmi-codec.c
+++ b/sound/soc/codecs/hdmi-codec.c
@@ -274,7 +274,8 @@ struct hdmi_codec_priv {
uint8_t eld[MAX_ELD_BYTES];
struct snd_pcm_chmap *chmap_info;
unsigned int chmap_idx;
- unsigned long busy;
+ struct mutex lock;
+ bool busy;
struct snd_soc_jack *jack;
unsigned int jack_status;
};
@@ -390,12 +391,15 @@ static int hdmi_codec_startup(struct snd_pcm_substream *substream,
struct hdmi_codec_priv *hcp = snd_soc_dai_get_drvdata(dai);
int ret = 0;
- ret = test_and_set_bit(0, &hcp->busy);
- if (ret) {
+ mutex_lock(&hcp->lock);
+ if (hcp->busy) {
dev_err(dai->dev, "Only one simultaneous stream supported!\n");
+ mutex_unlock(&hcp->lock);
return -EINVAL;
}
+ hcp->busy = true;
+
if (hcp->hcd.ops->audio_startup) {
ret = hcp->hcd.ops->audio_startup(dai->dev->parent, hcp->hcd.data);
if (ret)
@@ -415,11 +419,12 @@ static int hdmi_codec_startup(struct snd_pcm_substream *substream,
/* Select chmap supported */
hdmi_codec_eld_chmap(hcp);
}
- return 0;
err:
- /* Release the exclusive lock on error */
- clear_bit(0, &hcp->busy);
+ if (ret)
+ hcp->busy = false;
+
+ mutex_unlock(&hcp->lock);
return ret;
}
@@ -431,7 +436,9 @@ static void hdmi_codec_shutdown(struct snd_pcm_substream *substream,
hcp->chmap_idx = HDMI_CODEC_CHMAP_IDX_UNKNOWN;
hcp->hcd.ops->audio_shutdown(dai->dev->parent, hcp->hcd.data);
- clear_bit(0, &hcp->busy);
+ mutex_lock(&hcp->lock);
+ hcp->busy = false;
+ mutex_unlock(&hcp->lock);
}
static int hdmi_codec_hw_params(struct snd_pcm_substream *substream,
@@ -811,6 +818,8 @@ static int hdmi_codec_probe(struct platform_device *pdev)
return -ENOMEM;
hcp->hcd = *hcd;
+ mutex_init(&hcp->lock);
+
daidrv = devm_kcalloc(dev, dai_count, sizeof(*daidrv), GFP_KERNEL);
if (!daidrv)
return -ENOMEM;
--
2.21.0
next prev parent reply other threads:[~2019-10-23 16:12 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-23 16:12 [PATCH 0/2] ASoC: hdmi-codec: fix locking issue Jerome Brunet
2019-10-23 16:12 ` [PATCH 1/2] Revert "ASoC: hdmi-codec: re-introduce mutex locking" Jerome Brunet
2019-10-23 16:37 ` Mark Brown
2019-10-23 18:26 ` Russell King - ARM Linux admin
2019-10-23 18:46 ` Mark Brown
2019-10-23 18:56 ` Applied "ASoC: hdmi-codec: drop mutex locking again" to the asoc tree Mark Brown
2019-10-23 16:12 ` Jerome Brunet [this message]
2019-10-23 16:23 ` [alsa-devel] [PATCH 0/2] ASoC: hdmi-codec: fix locking issue Takashi Iwai
2019-10-23 17:53 ` Jerome Brunet
2019-10-24 11:34 ` Mark Brown
2019-10-24 12:15 ` Takashi Iwai
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20191023161203.28955-3-jbrunet@baylibre.com \
--to=jbrunet@baylibre.com \
--cc=alsa-devel@alsa-project.org \
--cc=broonie@kernel.org \
--cc=lgirdwood@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=rmk+kernel@armlinux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®