Skip to content

Commit

Permalink
ASoC: Intel: sof_sdw: Allocate snd_soc_card dynamically
Browse files Browse the repository at this point in the history
The static card_sof_sdw struct is modified during runtime and in case the
module is not removed, but the card is, then the next time the card is
created the card_sof_sdw will contain information from the previous card
which might lead to hard to debug issues, side effects.

Move the snd_soc_card into mc_private and use that to make sure that the
card is initialized correctly.

Signed-off-by: Peter Ujfalusi <[email protected]>
  • Loading branch information
ujfalusi committed Apr 17, 2024
1 parent e182080 commit 4ede2a0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
20 changes: 9 additions & 11 deletions sound/soc/intel/boards/sof_sdw.c
Original file line number Diff line number Diff line change
Expand Up @@ -1892,12 +1892,6 @@ static int sof_sdw_card_late_probe(struct snd_soc_card *card)
/* SoC card */
static const char sdw_card_long_name[] = "Intel Soundwire SOF";

static struct snd_soc_card card_sof_sdw = {
.name = "soundwire",
.owner = THIS_MODULE,
.late_probe = sof_sdw_card_late_probe,
};

/* helper to get the link that the codec DAI is used */
static struct snd_soc_dai_link *mc_find_codec_dai_used(struct snd_soc_card *card,
const char *dai_name)
Expand Down Expand Up @@ -1949,20 +1943,24 @@ static void mc_dailink_exit_loop(struct snd_soc_card *card)

static int mc_probe(struct platform_device *pdev)
{
struct snd_soc_card *card = &card_sof_sdw;
struct snd_soc_acpi_mach *mach = dev_get_platdata(&pdev->dev);
struct snd_soc_card *card;
struct mc_private *ctx;
int amp_num = 0, i;
int ret;

card->dev = &pdev->dev;

dev_dbg(card->dev, "Entry\n");
dev_dbg(&pdev->dev, "Entry\n");

ctx = devm_kzalloc(card->dev, sizeof(*ctx), GFP_KERNEL);
ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL);
if (!ctx)
return -ENOMEM;

card = &ctx->card;
card->dev = &pdev->dev;
card->name = "soundwire",
card->owner = THIS_MODULE,
card->late_probe = sof_sdw_card_late_probe,

snd_soc_card_set_drvdata(card, ctx);

dmi_check_system(sof_sdw_quirk_table);
Expand Down
1 change: 1 addition & 0 deletions sound/soc/intel/boards/sof_sdw_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ struct sof_sdw_codec_info {
};

struct mc_private {
struct snd_soc_card card;
struct snd_soc_jack sdw_headset;
struct sof_hdmi_private hdmi;
struct device *headset_codec_dev; /* only one headset per card */
Expand Down

0 comments on commit 4ede2a0

Please sign in to comment.