All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ricard Wanderlof <ricard.wanderlof@axis.com>
To: Mark Brown <broonie@kernel.org>, Liam Girdwood <lgirdwood@gmail.com>
Cc: alsa-devel <alsa-devel@alsa-project.org>
Subject: [PATCH] ASoC: Fail card instantiation if DAI format setup fails
Date: Wed, 24 Jul 2019 11:38:44 +0200	[thread overview]
Message-ID: <alpine.DEB.2.20.1907241132350.6338@lnxricardw1.se.axis.com> (raw)


If the DAI format setup fails, there is no valid communication format
between CPU and CODEC, so fail card instantiation, rather than continue
with a card that will most likely not function properly.

Signed-off-by: Ricard Wanderlof <ricardw@axis.com>
---

I've had the problem of a sound card coming up even though an incorrect 
DAI format was selected in the devicetree, apparently caused by not 
checking the return value of snd_soc_runtime_set_dai_fmt() when the card 
is instantiated, with the result in this particular case that that the 
audio data was not transferred correctly (capture data was shifted one bit 
up).

I'm unsure though if this is intentional, I can't think why it should be, 
since the DAI format is only set up at this time and not for instance 
later when a stream is enabled, but perhaps I'm missing something here.

At any rate, with this patch, the card does not come up under these 
circumstances. The error message from snd_soc_runtime_set_dai_fmt() is 
still printed to the kernel log so it's possible to see what the reason 
is.

/Ricard

 sound/soc/soc-core.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index 7ecfe641ca46..06697b2d96b1 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -1511,8 +1511,11 @@ static int soc_probe_link_dais(struct snd_soc_card *card,
 		}
 	}
 
-	if (dai_link->dai_fmt)
-		snd_soc_runtime_set_dai_fmt(rtd, dai_link->dai_fmt);
+	if (dai_link->dai_fmt) {
+		ret = snd_soc_runtime_set_dai_fmt(rtd, dai_link->dai_fmt);
+		if (ret)
+			return ret;
+	}
 
 	ret = soc_post_component_init(rtd, dai_link->name);
 	if (ret)
-- 
2.11.0


-- 
Ricard Wolf Wanderlof                           ricardw(at)axis.com
Axis Communications AB, Lund, Sweden            www.axis.com
Phone +46 46 272 2016                           Fax +46 46 13 61 30

             reply	other threads:[~2019-07-24  9:38 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-24  9:38 Ricard Wanderlof [this message]
2019-07-24 19:17 ` Applied "ASoC: Fail card instantiation if DAI format setup fails" to the asoc tree Mark Brown

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=alpine.DEB.2.20.1907241132350.6338@lnxricardw1.se.axis.com \
    --to=ricard.wanderlof@axis.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    --cc=lgirdwood@gmail.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.