Skip to content

Commit 33e59e5

Browse files
ujfalusibroonie
authored andcommitted
ASoC: Intel: skl_hda_dsp_generic: Allocate snd_soc_card dynamically
The static hda_soc_card might be modified during runtime which might cause issues on next time when the card is created. For example if the dmic_num was set with module parameter then removed for the next module loading then the card's components will still going to point to the previous boot's cfg-dmics:X string. There might be other places where devm allocated memory have been freed but the hda_soc_card still pointing to the now unallocated memory (the memory is freed when the platform device is removed). Fix this issue by moving the snd_soc_card into skl_hda_private and use it for the card registration to ensure that it is correctly initialized every time. Reviewed-by: Bard Liao <yung-chuan.liao@linux.intel.com> Reviewed-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com> Reviewed-by: Kai Vehmanen <kai.vehmanen@linux.intel.com> Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com> Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com> Link: https://lore.kernel.org/r/20240426152123.36284-2-pierre-louis.bossart@linux.intel.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 466c8c4 commit 33e59e5

2 files changed

Lines changed: 22 additions & 21 deletions

File tree

sound/soc/intel/boards/skl_hda_dsp_common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ struct skl_hda_hdmi_pcm {
2828
};
2929

3030
struct skl_hda_private {
31+
struct snd_soc_card card;
3132
struct list_head hdmi_pcm_list;
3233
int pcm_count;
3334
int dai_index;

sound/soc/intel/boards/skl_hda_dsp_generic.c

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -92,17 +92,6 @@ skl_hda_add_dai_link(struct snd_soc_card *card, struct snd_soc_dai_link *link)
9292
return ret;
9393
}
9494

95-
static struct snd_soc_card hda_soc_card = {
96-
.name = "hda-dsp",
97-
.owner = THIS_MODULE,
98-
.dai_link = skl_hda_be_dai_links,
99-
.dapm_widgets = skl_hda_widgets,
100-
.dapm_routes = skl_hda_map,
101-
.add_dai_link = skl_hda_add_dai_link,
102-
.fully_routed = true,
103-
.late_probe = skl_hda_card_late_probe,
104-
};
105-
10695
static char hda_soc_components[30];
10796

10897
#define IDISP_DAI_COUNT 3
@@ -115,9 +104,9 @@ static char hda_soc_components[30];
115104

116105
#define HDA_CODEC_AUTOSUSPEND_DELAY_MS 1000
117106

118-
static int skl_hda_fill_card_info(struct snd_soc_acpi_mach_params *mach_params)
107+
static int skl_hda_fill_card_info(struct snd_soc_card *card,
108+
struct snd_soc_acpi_mach_params *mach_params)
119109
{
120-
struct snd_soc_card *card = &hda_soc_card;
121110
struct skl_hda_private *ctx = snd_soc_card_get_drvdata(card);
122111
struct snd_soc_dai_link *dai_link;
123112
u32 codec_count, codec_mask;
@@ -199,6 +188,7 @@ static int skl_hda_audio_probe(struct platform_device *pdev)
199188
{
200189
struct snd_soc_acpi_mach *mach;
201190
struct skl_hda_private *ctx;
191+
struct snd_soc_card *card;
202192
int ret;
203193

204194
dev_dbg(&pdev->dev, "entry\n");
@@ -213,32 +203,42 @@ static int skl_hda_audio_probe(struct platform_device *pdev)
213203
if (!mach)
214204
return -EINVAL;
215205

216-
snd_soc_card_set_drvdata(&hda_soc_card, ctx);
206+
card = &ctx->card;
207+
card->name = "hda-dsp",
208+
card->owner = THIS_MODULE,
209+
card->dai_link = skl_hda_be_dai_links,
210+
card->dapm_widgets = skl_hda_widgets,
211+
card->dapm_routes = skl_hda_map,
212+
card->add_dai_link = skl_hda_add_dai_link,
213+
card->fully_routed = true,
214+
card->late_probe = skl_hda_card_late_probe,
215+
216+
snd_soc_card_set_drvdata(card, ctx);
217217

218-
ret = skl_hda_fill_card_info(&mach->mach_params);
218+
ret = skl_hda_fill_card_info(card, &mach->mach_params);
219219
if (ret < 0) {
220220
dev_err(&pdev->dev, "Unsupported HDAudio/iDisp configuration found\n");
221221
return ret;
222222
}
223223

224-
ctx->pcm_count = hda_soc_card.num_links;
224+
ctx->pcm_count = card->num_links;
225225
ctx->dai_index = 1; /* hdmi codec dai name starts from index 1 */
226226
ctx->platform_name = mach->mach_params.platform;
227227
ctx->common_hdmi_codec_drv = mach->mach_params.common_hdmi_codec_drv;
228228

229-
hda_soc_card.dev = &pdev->dev;
229+
card->dev = &pdev->dev;
230230
if (!snd_soc_acpi_sof_parent(&pdev->dev))
231-
hda_soc_card.disable_route_checks = true;
231+
card->disable_route_checks = true;
232232

233233
if (mach->mach_params.dmic_num > 0) {
234234
snprintf(hda_soc_components, sizeof(hda_soc_components),
235235
"cfg-dmics:%d", mach->mach_params.dmic_num);
236-
hda_soc_card.components = hda_soc_components;
236+
card->components = hda_soc_components;
237237
}
238238

239-
ret = devm_snd_soc_register_card(&pdev->dev, &hda_soc_card);
239+
ret = devm_snd_soc_register_card(&pdev->dev, card);
240240
if (!ret)
241-
skl_set_hda_codec_autosuspend_delay(&hda_soc_card);
241+
skl_set_hda_codec_autosuspend_delay(card);
242242

243243
return ret;
244244
}

0 commit comments

Comments
 (0)