Skip to content

Commit

Permalink
ASoC: soc-pcm: cleanup soc_pcm_params_symmetry()
Browse files Browse the repository at this point in the history
soc_pcm_params_symmetry() checks rate/channel/sample_bits state.
These are very similar but different, thus, it needs to have very
verbose code.
This patch use macro for it and make code more simple.

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Link: https://lore.kernel.org/r/878s8un6si.wl-kuninori.morimoto.gx@renesas.com
Signed-off-by: Mark Brown <broonie@kernel.org>
  • Loading branch information
Kuninori Morimoto authored and Mark Brown committed Jan 21, 2021
1 parent fac110c commit 3a90672
Showing 1 changed file with 15 additions and 45 deletions.
60 changes: 15 additions & 45 deletions sound/soc/soc-pcm.c
Original file line number Diff line number Diff line change
Expand Up @@ -384,53 +384,23 @@ static int soc_pcm_params_symmetry(struct snd_pcm_substream *substream,

soc_pcm_set_dai_params(&d, params);

/* reject unmatched parameters when applying symmetry */
symmetry = rtd->dai_link->symmetric_rate;

for_each_rtd_cpu_dais(rtd, i, dai)
symmetry |= dai->driver->symmetric_rate;

if (symmetry) {
for_each_rtd_cpu_dais(rtd, i, cpu_dai) {
if (cpu_dai->rate && cpu_dai->rate != d.rate) {
dev_err(rtd->dev, "ASoC: unmatched rate symmetry: %d - %d\n",
cpu_dai->rate, d.rate);
return -EINVAL;
}
}
}

symmetry = rtd->dai_link->symmetric_channels;

for_each_rtd_dais(rtd, i, dai)
symmetry |= dai->driver->symmetric_channels;

if (symmetry) {
for_each_rtd_cpu_dais(rtd, i, cpu_dai) {
if (cpu_dai->channels &&
cpu_dai->channels != d.channels) {
dev_err(rtd->dev, "ASoC: unmatched channel symmetry: %d - %d\n",
cpu_dai->channels, d.channels);
return -EINVAL;
#define __soc_pcm_params_symmetry(name) \
symmetry = rtd->dai_link->symmetric_##name; \
for_each_rtd_dais(rtd, i, dai) \
symmetry |= dai->driver->symmetric_##name; \
\
if (symmetry) \
for_each_rtd_cpu_dais(rtd, i, cpu_dai) \
if (cpu_dai->name && cpu_dai->name != d.name) { \
dev_err(rtd->dev, "ASoC: unmatched %s symmetry: %d - %d\n", \
#name, cpu_dai->name, d.name); \
return -EINVAL; \
}
}
}

symmetry = rtd->dai_link->symmetric_sample_bits;

for_each_rtd_dais(rtd, i, dai)
symmetry |= dai->driver->symmetric_sample_bits;

if (symmetry) {
for_each_rtd_cpu_dais(rtd, i, cpu_dai) {
if (cpu_dai->sample_bits &&
cpu_dai->sample_bits != d.sample_bits) {
dev_err(rtd->dev, "ASoC: unmatched sample bits symmetry: %d - %d\n",
cpu_dai->sample_bits, d.sample_bits);
return -EINVAL;
}
}
}
/* reject unmatched parameters when applying symmetry */
__soc_pcm_params_symmetry(rate);
__soc_pcm_params_symmetry(channels);
__soc_pcm_params_symmetry(sample_bits);

return 0;
}
Expand Down

0 comments on commit 3a90672

Please sign in to comment.