Skip to content

Commit c78af34

Browse files
geertugregkh
authored andcommitted
ASoC: simple-card: Fix crash in asoc_simple_card_unref()
commit 7ddfdb5 upstream. If asoc_simple_card_probe() fails, asoc_simple_card_unref() may be called before dev_set_drvdata(), causing a NULL pointer dereference in asoc_simple_card_unref(): Unable to handle kernel NULL pointer dereference at virtual address 000000d4 ... PC is at asoc_simple_card_unref+0x14/0x48 LR is at asoc_simple_card_probe+0x3d4/0x40c This typically happens because asoc_simple_card_parse_of() returns -EPROBE_DEFER, but other failure modes are possible. devm_snd_soc_register_card()/snd_soc_register_card() may fail either before or after dev_set_drvdata(). Pass a snd_soc_card pointer instead of a platform_device pointer to asoc_simple_card_unref() to fix this. Note that if CONFIG_OF_DYNAMIC=n, of_node_put() is a dummy, and gcc may optimize away the loop over card->dai_link, never actually dereferencing card, and thus avoiding the crash... Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be> Fixes: e512e00 ("ASoC: simple-card: Fix the reference count of device nodes") Signed-off-by: Mark Brown <broonie@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 971784f commit c78af34

1 file changed

Lines changed: 3 additions & 4 deletions

File tree

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -453,9 +453,8 @@ static int asoc_simple_card_parse_of(struct device_node *node,
453453
}
454454

455455
/* Decrease the reference count of the device nodes */
456-
static int asoc_simple_card_unref(struct platform_device *pdev)
456+
static int asoc_simple_card_unref(struct snd_soc_card *card)
457457
{
458-
struct snd_soc_card *card = platform_get_drvdata(pdev);
459458
struct snd_soc_dai_link *dai_link;
460459
struct device_node *np;
461460
int num_links;
@@ -562,7 +561,7 @@ static int asoc_simple_card_probe(struct platform_device *pdev)
562561
return ret;
563562

564563
err:
565-
asoc_simple_card_unref(pdev);
564+
asoc_simple_card_unref(&priv->snd_card);
566565
return ret;
567566
}
568567

@@ -578,7 +577,7 @@ static int asoc_simple_card_remove(struct platform_device *pdev)
578577
snd_soc_jack_free_gpios(&simple_card_mic_jack, 1,
579578
&simple_card_mic_jack_gpio);
580579

581-
return asoc_simple_card_unref(pdev);
580+
return asoc_simple_card_unref(card);
582581
}
583582

584583
static const struct of_device_id asoc_simple_of_match[] = {

0 commit comments

Comments
 (0)