Skip to content

Commit 04e97fa

Browse files
LaurentiuM1234broonie
authored andcommitted
ASoC: simple-card-utils: fix priv->dai_props indexing
As of commit cb18cd2 ("ASoC: soc-core: do rtd->id trick at snd_soc_add_pcm_runtime()") the ID stored in the PCM runtime data can no longer be safely used to index the priv->dai_props array. This is because the ID may be modified during snd_soc_add_pcm_runtime(), thus resulting in an ID that's no longer a valid array index. To fix this, use the position of the dai_link stored inside the PCM runtime data relative to the start of the dai_link array as index into the priv->dai_props array. Signed-off-by: Laurentiu Mihalcea <[email protected]> Acked-by: Kuninori Morimoto <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent d5a4d7f commit 04e97fa

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

include/sound/simple_card_utils.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,13 @@ struct simple_util_priv {
8989
#define simple_props_to_dai_codec(props, i) ((props)->codec_dai + i)
9090
#define simple_props_to_codec_conf(props, i) ((props)->codec_conf + i)
9191

92+
/* has the same effect as simple_priv_to_props(). Preferred over
93+
* simple_priv_to_props() when dealing with PCM runtime data as
94+
* the ID stored in rtd->id may not be a valid array index.
95+
*/
96+
#define runtime_simple_priv_to_props(priv, rtd) \
97+
((priv)->dai_props + ((rtd)->dai_link - (priv)->dai_link))
98+
9299
#define for_each_prop_dlc_cpus(props, i, cpu) \
93100
for ((i) = 0; \
94101
((i) < (props)->num.cpus) && \

sound/soc/generic/simple-card-utils.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ int simple_util_startup(struct snd_pcm_substream *substream)
296296
{
297297
struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
298298
struct simple_util_priv *priv = snd_soc_card_get_drvdata(rtd->card);
299-
struct simple_dai_props *props = simple_priv_to_props(priv, rtd->id);
299+
struct simple_dai_props *props = runtime_simple_priv_to_props(priv, rtd);
300300
struct simple_util_dai *dai;
301301
unsigned int fixed_sysclk = 0;
302302
int i1, i2, i;
@@ -357,7 +357,7 @@ void simple_util_shutdown(struct snd_pcm_substream *substream)
357357
{
358358
struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
359359
struct simple_util_priv *priv = snd_soc_card_get_drvdata(rtd->card);
360-
struct simple_dai_props *props = simple_priv_to_props(priv, rtd->id);
360+
struct simple_dai_props *props = runtime_simple_priv_to_props(priv, rtd);
361361
struct simple_util_dai *dai;
362362
int i;
363363

@@ -448,7 +448,7 @@ int simple_util_hw_params(struct snd_pcm_substream *substream,
448448
struct simple_util_dai *pdai;
449449
struct snd_soc_dai *sdai;
450450
struct simple_util_priv *priv = snd_soc_card_get_drvdata(rtd->card);
451-
struct simple_dai_props *props = simple_priv_to_props(priv, rtd->id);
451+
struct simple_dai_props *props = runtime_simple_priv_to_props(priv, rtd);
452452
unsigned int mclk, mclk_fs = 0;
453453
int i, ret;
454454

@@ -517,7 +517,7 @@ int simple_util_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
517517
struct snd_pcm_hw_params *params)
518518
{
519519
struct simple_util_priv *priv = snd_soc_card_get_drvdata(rtd->card);
520-
struct simple_dai_props *dai_props = simple_priv_to_props(priv, rtd->id);
520+
struct simple_dai_props *dai_props = runtime_simple_priv_to_props(priv, rtd);
521521
struct simple_util_data *data = &dai_props->adata;
522522
struct snd_interval *rate = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
523523
struct snd_interval *channels = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
@@ -628,7 +628,7 @@ static int simple_init_for_codec2codec(struct snd_soc_pcm_runtime *rtd,
628628
int simple_util_dai_init(struct snd_soc_pcm_runtime *rtd)
629629
{
630630
struct simple_util_priv *priv = snd_soc_card_get_drvdata(rtd->card);
631-
struct simple_dai_props *props = simple_priv_to_props(priv, rtd->id);
631+
struct simple_dai_props *props = runtime_simple_priv_to_props(priv, rtd);
632632
struct simple_util_dai *dai;
633633
int i, ret;
634634

0 commit comments

Comments
 (0)