[alsa-devel] [PATCH 0/2] ASoC: fix hw_params/hw_free validity checks
While working on a codec, I have found an odd situation. The hw_params callback which was provided by the codec dai was not called as expected. However, the hw_free callback was called, even if hw_params was skipped.
After debugging, I found out that the dai was considered invalid because it did not specify any rates, only rate_min and rate_max. That's a first problem.
If a codec dai is considered invalid, hw_free should probably not be called either, that's a 2nd issue.
This patchset is meant to solve both issues.
Jerome Brunet (2): ASoC: fix valid stream condition ASoC: skip hw_free on codec dai for which the stream is invalid
sound/soc/soc-pcm.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
A stream may specify a rate range using 'rate_min' and 'rate_max', so a stream may be valid and not specify any rates. However, as stream cannot be valid and not have any channel. Let's use this condition instead to determine if a stream is valid or not.
Fixes: cde79035c6cf ("ASoC: Handle multiple codecs with split playback / capture") Signed-off-by: Jerome Brunet jbrunet@baylibre.com --- sound/soc/soc-pcm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c index 99bbd724d2a6..263086af707d 100644 --- a/sound/soc/soc-pcm.c +++ b/sound/soc/soc-pcm.c @@ -42,8 +42,8 @@ static bool snd_soc_dai_stream_valid(struct snd_soc_dai *dai, int stream) else codec_stream = &dai->driver->capture;
- /* If the codec specifies any rate at all, it supports the stream. */ - return codec_stream->rates; + /* If the codec specifies any channels at all, it supports the stream */ + return codec_stream->channels_min; }
/**
Like for hw_params, hw_free should not be called on codec dai for which the current stream is invalid.
Fixes: cde79035c6cf ("ASoC: Handle multiple codecs with split playback / capture") Signed-off-by: Jerome Brunet jbrunet@baylibre.com --- sound/soc/soc-pcm.c | 6 ++++++ 1 file changed, 6 insertions(+)
diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c index 263086af707d..04ccdc59295d 100644 --- a/sound/soc/soc-pcm.c +++ b/sound/soc/soc-pcm.c @@ -1020,6 +1020,9 @@ static int soc_pcm_hw_params(struct snd_pcm_substream *substream,
codec_err: for_each_rtd_codec_dai_rollback(rtd, i, codec_dai) { + if (!snd_soc_dai_stream_valid(codec_dai, substream->stream)) + continue; + if (codec_dai->driver->ops->hw_free) codec_dai->driver->ops->hw_free(substream, codec_dai); codec_dai->rate = 0; @@ -1077,6 +1080,9 @@ static int soc_pcm_hw_free(struct snd_pcm_substream *substream)
/* now free hw params for the DAIs */ for_each_rtd_codec_dai(rtd, i, codec_dai) { + if (!snd_soc_dai_stream_valid(codec_dai, substream->stream)) + continue; + if (codec_dai->driver->ops->hw_free) codec_dai->driver->ops->hw_free(substream, codec_dai); }
participants (1)
-
Jerome Brunet