Skip to content

Commit 3fcf94e

Browse files
jbrun3tbroonie
authored andcommitted
ASoC: hdmi-codec: remove reference to the current substream
If the hdmi-codec is on a codec-to-codec link, the substream pointer it receives is completely made up by snd_soc_dai_link_event(). The pointer will be different between startup() and shutdown(). The hdmi-codec complains when this happens even if it is not really a problem. The current_substream pointer is not used for anything useful apart from getting the exclusive ownership of the device. Remove current_substream pointer and replace the exclusive locking mechanism with a simple variable and some atomic operations. Signed-off-by: Jerome Brunet <jbrunet@baylibre.com> Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 900e5da commit 3fcf94e

File tree

1 file changed

+16
-42
lines changed

1 file changed

+16
-42
lines changed

sound/soc/codecs/hdmi-codec.c

Lines changed: 16 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -280,11 +280,10 @@ struct hdmi_codec_priv {
280280
struct hdmi_codec_pdata hcd;
281281
struct snd_soc_dai_driver *daidrv;
282282
struct hdmi_codec_daifmt daifmt[2];
283-
struct mutex current_stream_lock;
284-
struct snd_pcm_substream *current_stream;
285283
uint8_t eld[MAX_ELD_BYTES];
286284
struct snd_pcm_chmap *chmap_info;
287285
unsigned int chmap_idx;
286+
unsigned long busy;
288287
};
289288

290289
static const struct snd_soc_dapm_widget hdmi_widgets[] = {
@@ -392,42 +391,22 @@ static int hdmi_codec_chmap_ctl_get(struct snd_kcontrol *kcontrol,
392391
return 0;
393392
}
394393

395-
static int hdmi_codec_new_stream(struct snd_pcm_substream *substream,
396-
struct snd_soc_dai *dai)
397-
{
398-
struct hdmi_codec_priv *hcp = snd_soc_dai_get_drvdata(dai);
399-
int ret = 0;
400-
401-
mutex_lock(&hcp->current_stream_lock);
402-
if (!hcp->current_stream) {
403-
hcp->current_stream = substream;
404-
} else if (hcp->current_stream != substream) {
405-
dev_err(dai->dev, "Only one simultaneous stream supported!\n");
406-
ret = -EINVAL;
407-
}
408-
mutex_unlock(&hcp->current_stream_lock);
409-
410-
return ret;
411-
}
412-
413394
static int hdmi_codec_startup(struct snd_pcm_substream *substream,
414395
struct snd_soc_dai *dai)
415396
{
416397
struct hdmi_codec_priv *hcp = snd_soc_dai_get_drvdata(dai);
417398
int ret = 0;
418399

419-
ret = hdmi_codec_new_stream(substream, dai);
420-
if (ret)
421-
return ret;
400+
ret = test_and_set_bit(0, &hcp->busy);
401+
if (ret) {
402+
dev_err(dai->dev, "Only one simultaneous stream supported!\n");
403+
return -EINVAL;
404+
}
422405

423406
if (hcp->hcd.ops->audio_startup) {
424407
ret = hcp->hcd.ops->audio_startup(dai->dev->parent, hcp->hcd.data);
425-
if (ret) {
426-
mutex_lock(&hcp->current_stream_lock);
427-
hcp->current_stream = NULL;
428-
mutex_unlock(&hcp->current_stream_lock);
429-
return ret;
430-
}
408+
if (ret)
409+
goto err;
431410
}
432411

433412
if (hcp->hcd.ops->get_eld) {
@@ -437,32 +416,29 @@ static int hdmi_codec_startup(struct snd_pcm_substream *substream,
437416
if (!ret) {
438417
ret = snd_pcm_hw_constraint_eld(substream->runtime,
439418
hcp->eld);
440-
if (ret) {
441-
mutex_lock(&hcp->current_stream_lock);
442-
hcp->current_stream = NULL;
443-
mutex_unlock(&hcp->current_stream_lock);
444-
return ret;
445-
}
419+
if (ret)
420+
goto err;
446421
}
447422
/* Select chmap supported */
448423
hdmi_codec_eld_chmap(hcp);
449424
}
450425
return 0;
426+
427+
err:
428+
/* Release the exclusive lock on error */
429+
clear_bit(0, &hcp->busy);
430+
return ret;
451431
}
452432

453433
static void hdmi_codec_shutdown(struct snd_pcm_substream *substream,
454434
struct snd_soc_dai *dai)
455435
{
456436
struct hdmi_codec_priv *hcp = snd_soc_dai_get_drvdata(dai);
457437

458-
WARN_ON(hcp->current_stream != substream);
459-
460438
hcp->chmap_idx = HDMI_CODEC_CHMAP_IDX_UNKNOWN;
461439
hcp->hcd.ops->audio_shutdown(dai->dev->parent, hcp->hcd.data);
462440

463-
mutex_lock(&hcp->current_stream_lock);
464-
hcp->current_stream = NULL;
465-
mutex_unlock(&hcp->current_stream_lock);
441+
clear_bit(0, &hcp->busy);
466442
}
467443

468444
static int hdmi_codec_hw_params(struct snd_pcm_substream *substream,
@@ -761,8 +737,6 @@ static int hdmi_codec_probe(struct platform_device *pdev)
761737
return -ENOMEM;
762738

763739
hcp->hcd = *hcd;
764-
mutex_init(&hcp->current_stream_lock);
765-
766740
hcp->daidrv = devm_kcalloc(dev, dai_count, sizeof(*hcp->daidrv),
767741
GFP_KERNEL);
768742
if (!hcp->daidrv)

0 commit comments

Comments
 (0)