[PATCH 0/5] soc-pcm: tidyup snd_pcm_hardware setup for FE/BE
Hi Mark
These patches tidyup snd_pcm_hardware setup for FE/BE. [1/5] changes behavior, but I think it is bug-fix.
Kuninori Morimoto (5): ASoC: soc-pcm: remove strange format storing ASoC: soc-pcm: unpack dpcm_init_runtime_hw() ASoC: soc-pcm: add dpcm_runtime_setup_fe() ASoC: soc-pcm: add dpcm_runtime_setup() ASoC: soc-pcm: unpack dpcm_set_fe_runtime()
sound/soc/soc-pcm.c | 79 +++++++++++++++++++++------------------------ 1 file changed, 36 insertions(+), 43 deletions(-)
From: Kuninori Morimoto kuninori.morimoto.gx@renesas.com
dpcm_init_runtime_hw() (= A) is used from dpcm_set_fe_runtime() (= B) with for_each_rtd_cpu_dais() loop (= C), and it checks formats (= D).
(A) static void dpcm_init_runtime_hw(...) { ... ^ if (runtime->hw.formats) | (D1) runtime->hw.formats &= stream->formats; (D) else | (D2) runtime->hw.formats = stream->formats; v }
(B) static void dpcm_set_fe_runtime(...) { ... (C) for_each_rtd_cpu_dais(rtd, i, cpu_dai) { ... (A) dpcm_init_runtime_hw(...); } }
If this for_each_rtd_cpu_dais() loop (= C) calls dpcm_init_runtime_hw() (= A) multiple times, this means it is Multi-CPU.
If we focus to format operation at (D), using mask (= D1) is understandable because it restricts unsupported format. But, enabling format when zero format case (= D2) is very strange, because it might enables unsupported format.
This runtime->hw.formats is initialized by ULLONG_MAX at soc_pcm_hw_init(), thus becoming zero format means it can't use such format. And doing this strange format operation is only here.
This patch removes strange format operation (= D2), and use standard soc_pcm_hw_update_format() for it.
Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com --- sound/soc/soc-pcm.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c index 14d85ca1e435..bb912a94e895 100644 --- a/sound/soc/soc-pcm.c +++ b/sound/soc/soc-pcm.c @@ -1533,10 +1533,7 @@ static void dpcm_init_runtime_hw(struct snd_pcm_runtime *runtime,
soc_pcm_hw_update_rate(hw, stream); soc_pcm_hw_update_chan(hw, stream); - if (runtime->hw.formats) - runtime->hw.formats &= stream->formats; - else - runtime->hw.formats = stream->formats; + soc_pcm_hw_update_format(hw, stream); }
static void dpcm_runtime_merge_format(struct snd_pcm_substream *substream,
From: Kuninori Morimoto kuninori.morimoto.gx@renesas.com
dpcm_init_runtime_hw() is now just verbose function. This patch unpacks it.
Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com --- sound/soc/soc-pcm.c | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-)
diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c index bb912a94e895..fd279fb28533 100644 --- a/sound/soc/soc-pcm.c +++ b/sound/soc/soc-pcm.c @@ -1526,16 +1526,6 @@ int dpcm_be_dai_startup(struct snd_soc_pcm_runtime *fe, int stream) return err; }
-static void dpcm_init_runtime_hw(struct snd_pcm_runtime *runtime, - struct snd_soc_pcm_stream *stream) -{ - struct snd_pcm_hardware *hw = &runtime->hw; - - soc_pcm_hw_update_rate(hw, stream); - soc_pcm_hw_update_chan(hw, stream); - soc_pcm_hw_update_format(hw, stream); -} - static void dpcm_runtime_merge_format(struct snd_pcm_substream *substream, struct snd_pcm_runtime *runtime) { @@ -1669,6 +1659,8 @@ static void dpcm_set_fe_runtime(struct snd_pcm_substream *substream) soc_pcm_hw_init(hw);
for_each_rtd_cpu_dais(rtd, i, cpu_dai) { + struct snd_soc_pcm_stream *stream; + /* * Skip CPUs which don't support the current stream * type. See soc_pcm_init_runtime_hw() for more details @@ -1676,9 +1668,11 @@ static void dpcm_set_fe_runtime(struct snd_pcm_substream *substream) if (!snd_soc_dai_stream_valid(cpu_dai, substream->stream)) continue;
- dpcm_init_runtime_hw(runtime, - snd_soc_dai_get_pcm_stream(cpu_dai, - substream->stream)); + stream = snd_soc_dai_get_pcm_stream(cpu_dai, substream->stream); + + soc_pcm_hw_update_rate(hw, stream); + soc_pcm_hw_update_chan(hw, stream); + soc_pcm_hw_update_format(hw, stream); }
dpcm_runtime_merge_format(substream, runtime);
From: Kuninori Morimoto kuninori.morimoto.gx@renesas.com
dpcm_fe_dai_startup() (= A) calls dpcm_set_fe_runtime() (= B) to setup DPCM runtime. From *naming point of view*, it sounds like setup function for FE.
(A) static int dpcm_fe_dai_startup(...) { ... (B) dpcm_set_fe_runtime(...); ... }
But in dpcm_set_fe_runtime() (= B), It setups FE by for_each loop (= X), and setups BE by dpcm_runtime_merge_xxx() (= Y).
(B) static void dpcm_set_fe_runtime(...) { ... ^ for_each_rtd_cpu_dais(...) { | ... (X) soc_pcm_hw_update_rate(...); | soc_pcm_hw_update_chan(...); | soc_pcm_hw_update_format(...); v }
^ dpcm_runtime_merge_format(...); (Y) dpcm_runtime_merge_chan(...); v dpcm_runtime_merge_rate(...); }
These means that the function which is called as xxx_fe_xxx() is setups both FE and BE. This is confusable and can be hot bed for bug.
To tidyup it, as 1st step, this patch adds new dpcm_runtime_setup_fe() for (X).
Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com --- sound/soc/soc-pcm.c | 53 ++++++++++++++++++++++++++------------------- 1 file changed, 31 insertions(+), 22 deletions(-)
diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c index fd279fb28533..066218f1f075 100644 --- a/sound/soc/soc-pcm.c +++ b/sound/soc/soc-pcm.c @@ -1526,6 +1526,36 @@ int dpcm_be_dai_startup(struct snd_soc_pcm_runtime *fe, int stream) return err; }
+static void dpcm_runtime_setup_fe(struct snd_pcm_substream *substream) +{ + struct snd_soc_pcm_runtime *fe = asoc_substream_to_rtd(substream); + struct snd_pcm_runtime *runtime = substream->runtime; + struct snd_pcm_hardware *hw = &runtime->hw; + struct snd_soc_dai *dai; + int stream = substream->stream; + int i; + + soc_pcm_hw_init(hw); + + for_each_rtd_cpu_dais(fe, i, dai) { + struct snd_soc_pcm_stream *cpu_stream; + + /* + * Skip CPUs which don't support the current stream + * type. See soc_pcm_init_runtime_hw() for more details + */ + if (!snd_soc_dai_stream_valid(dai, stream)) + continue; + + cpu_stream = snd_soc_dai_get_pcm_stream(dai, stream); + + soc_pcm_hw_update_rate(hw, cpu_stream); + soc_pcm_hw_update_chan(hw, cpu_stream); + soc_pcm_hw_update_format(hw, cpu_stream); + } + +} + static void dpcm_runtime_merge_format(struct snd_pcm_substream *substream, struct snd_pcm_runtime *runtime) { @@ -1651,29 +1681,8 @@ static void dpcm_runtime_merge_rate(struct snd_pcm_substream *substream, static void dpcm_set_fe_runtime(struct snd_pcm_substream *substream) { struct snd_pcm_runtime *runtime = substream->runtime; - struct snd_pcm_hardware *hw = &runtime->hw; - struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); - struct snd_soc_dai *cpu_dai; - int i;
- soc_pcm_hw_init(hw); - - for_each_rtd_cpu_dais(rtd, i, cpu_dai) { - struct snd_soc_pcm_stream *stream; - - /* - * Skip CPUs which don't support the current stream - * type. See soc_pcm_init_runtime_hw() for more details - */ - if (!snd_soc_dai_stream_valid(cpu_dai, substream->stream)) - continue; - - stream = snd_soc_dai_get_pcm_stream(cpu_dai, substream->stream); - - soc_pcm_hw_update_rate(hw, stream); - soc_pcm_hw_update_chan(hw, stream); - soc_pcm_hw_update_format(hw, stream); - } + dpcm_runtime_setup_fe(substream);
dpcm_runtime_merge_format(substream, runtime); dpcm_runtime_merge_chan(substream, runtime);
From: Kuninori Morimoto kuninori.morimoto.gx@renesas.com
dpcm_fe_dai_startup() (= A) calls dpcm_set_fe_runtime() (= B) to setup DPCM runtime. From *naming point of view*, it sounds like setup function for FE.
(A) static int dpcm_fe_dai_startup(...) { ... (B) dpcm_set_fe_runtime(...); ... }
But in dpcm_set_fe_runtime() (= B), It setups FE by dpcm_runtime_setup_fe() (= X), and setups BE by dpcm_runtime_merge_xxx() (= Y).
(B) static void dpcm_set_fe_runtime(...) { ... (X) dpcm_runtime_setup_fe(...);
^ dpcm_runtime_merge_format(...); (Y) dpcm_runtime_merge_chan(...); v dpcm_runtime_merge_rate(...); }
These means that the function which is called as xxx_fe_xxx() is setups both FE and BE. This is confusable and can be hot bed for bug.
This patch renames unclear dpcm_runtime_merge_xxx() (= Y) to more clear dpcm_runtime_setup_be_xxx().
Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com --- sound/soc/soc-pcm.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-)
diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c index 066218f1f075..7fc7e3e24444 100644 --- a/sound/soc/soc-pcm.c +++ b/sound/soc/soc-pcm.c @@ -1556,10 +1556,10 @@ static void dpcm_runtime_setup_fe(struct snd_pcm_substream *substream)
}
-static void dpcm_runtime_merge_format(struct snd_pcm_substream *substream, - struct snd_pcm_runtime *runtime) +static void dpcm_runtime_setup_be_format(struct snd_pcm_substream *substream) { struct snd_soc_pcm_runtime *fe = asoc_substream_to_rtd(substream); + struct snd_pcm_runtime *runtime = substream->runtime; struct snd_pcm_hardware *hw = &runtime->hw; struct snd_soc_dpcm *dpcm; struct snd_soc_dai *dai; @@ -1593,10 +1593,10 @@ static void dpcm_runtime_merge_format(struct snd_pcm_substream *substream, } }
-static void dpcm_runtime_merge_chan(struct snd_pcm_substream *substream, - struct snd_pcm_runtime *runtime) +static void dpcm_runtime_setup_be_chan(struct snd_pcm_substream *substream) { struct snd_soc_pcm_runtime *fe = asoc_substream_to_rtd(substream); + struct snd_pcm_runtime *runtime = substream->runtime; struct snd_pcm_hardware *hw = &runtime->hw; struct snd_soc_dpcm *dpcm; int stream = substream->stream; @@ -1641,10 +1641,10 @@ static void dpcm_runtime_merge_chan(struct snd_pcm_substream *substream, } }
-static void dpcm_runtime_merge_rate(struct snd_pcm_substream *substream, - struct snd_pcm_runtime *runtime) +static void dpcm_runtime_setup_be_rate(struct snd_pcm_substream *substream) { struct snd_soc_pcm_runtime *fe = asoc_substream_to_rtd(substream); + struct snd_pcm_runtime *runtime = substream->runtime; struct snd_pcm_hardware *hw = &runtime->hw; struct snd_soc_dpcm *dpcm; int stream = substream->stream; @@ -1680,13 +1680,11 @@ static void dpcm_runtime_merge_rate(struct snd_pcm_substream *substream,
static void dpcm_set_fe_runtime(struct snd_pcm_substream *substream) { - struct snd_pcm_runtime *runtime = substream->runtime; - dpcm_runtime_setup_fe(substream);
- dpcm_runtime_merge_format(substream, runtime); - dpcm_runtime_merge_chan(substream, runtime); - dpcm_runtime_merge_rate(substream, runtime); + dpcm_runtime_setup_be_format(substream); + dpcm_runtime_setup_be_chan(substream); + dpcm_runtime_setup_be_rate(substream); }
static int dpcm_apply_symmetry(struct snd_pcm_substream *fe_substream,
From: Kuninori Morimoto kuninori.morimoto.gx@renesas.com
dpcm_fe_dai_startup() (= A) calls dpcm_set_fe_runtime() (= B) to setup DPCM runtime. From *naming point of view*, it sounds like setup function for FE.
(A) static int dpcm_fe_dai_startup(...) { ... (B) dpcm_set_fe_runtime(...); ... }
But in dpcm_set_fe_runtime() (= B), It setups FE by dpcm_runtime_setup_fe() (= X), and setups BE by dpcm_runtime_merge_xxx() (= Y).
(B) static void dpcm_set_fe_runtime(...) { ... (X) dpcm_runtime_setup_fe(...);
^ dpcm_runtime_setup_be_format(...); (Y) dpcm_runtime_setup_be_chan(...); v dpcm_runtime_setup_be_rate(...); }
These means that the function which is called as xxx_fe_xxx() is setups both FE and BE. This is confusable and can be hot bed for bug.
Now dpcm_set_fe_runtime() (= B) is simple enough and confusable naming, let's unpack it at dpcm_fe_dai_startup().
Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com --- sound/soc/soc-pcm.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-)
diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c index 7fc7e3e24444..511c9218308a 100644 --- a/sound/soc/soc-pcm.c +++ b/sound/soc/soc-pcm.c @@ -1678,15 +1678,6 @@ static void dpcm_runtime_setup_be_rate(struct snd_pcm_substream *substream) } }
-static void dpcm_set_fe_runtime(struct snd_pcm_substream *substream) -{ - dpcm_runtime_setup_fe(substream); - - dpcm_runtime_setup_be_format(substream); - dpcm_runtime_setup_be_chan(substream); - dpcm_runtime_setup_be_rate(substream); -} - static int dpcm_apply_symmetry(struct snd_pcm_substream *fe_substream, int stream) { @@ -1766,7 +1757,11 @@ static int dpcm_fe_dai_startup(struct snd_pcm_substream *fe_substream)
fe->dpcm[stream].state = SND_SOC_DPCM_STATE_OPEN;
- dpcm_set_fe_runtime(fe_substream); + dpcm_runtime_setup_fe(fe_substream); + + dpcm_runtime_setup_be_format(fe_substream); + dpcm_runtime_setup_be_chan(fe_substream); + dpcm_runtime_setup_be_rate(fe_substream);
ret = dpcm_apply_symmetry(fe_substream, stream); if (ret < 0)
On 22 Feb 2021 09:46:24 +0900, Kuninori Morimoto wrote:
These patches tidyup snd_pcm_hardware setup for FE/BE. [1/5] changes behavior, but I think it is bug-fix.
Kuninori Morimoto (5): ASoC: soc-pcm: remove strange format storing ASoC: soc-pcm: unpack dpcm_init_runtime_hw() ASoC: soc-pcm: add dpcm_runtime_setup_fe() ASoC: soc-pcm: add dpcm_runtime_setup() ASoC: soc-pcm: unpack dpcm_set_fe_runtime()
[...]
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next
Thanks!
[1/5] ASoC: soc-pcm: remove strange format storing commit: bae5b4aff2ddb784a536f1960ce415ac5c1ceed8 [2/5] ASoC: soc-pcm: unpack dpcm_init_runtime_hw() commit: 75c4b5945d017d4c3beb892a58498202a23803e9 [3/5] ASoC: soc-pcm: add dpcm_runtime_setup_fe() commit: 9337e738b96d37de3afa3333961a2af4a2b1dc9e [4/5] ASoC: soc-pcm: add dpcm_runtime_setup() commit: c813f6ed347cd610c239ff8027e8f403cd193648 [5/5] ASoC: soc-pcm: unpack dpcm_set_fe_runtime() commit: 6503916cefd802994870fe1e7cc6ad282549139e
All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying to this mail.
Thanks, Mark
participants (2)
-
Kuninori Morimoto
-
Mark Brown