]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
ASoC: simple-card: Fix crash in asoc_simple_card_unref()
authorGeert Uytterhoeven <geert+renesas@glider.be>
Tue, 13 Jan 2015 20:03:37 +0000 (21:03 +0100)
committerLuis Henriques <luis.henriques@canonical.com>
Wed, 4 Feb 2015 10:58:03 +0000 (10:58 +0000)
commit 7ddfdb5c5a5b51bdd2cb749d8341d763b079d520 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: e512e001dafa54e5 ("ASoC: simple-card: Fix the reference count of device nodes")
Signed-off-by: Mark Brown <broonie@kernel.org>
[ luis: backported to 3.16:
  - adjusted context
  - dropped changes to asoc_simple_card_remove() ]
Signed-off-by: Luis Henriques <luis.henriques@canonical.com>
sound/soc/generic/simple-card.c

index 03a7fdcdf114390abe3d694535c8c66f7d77e318..517a0ff64303038f3337d3acc41002eb7a022c8e 100644 (file)
@@ -357,9 +357,8 @@ static int asoc_simple_card_parse_of(struct device_node *node,
 }
 
 /* update the reference count of the devices nodes at end of probe */
-static int asoc_simple_card_unref(struct platform_device *pdev)
+static int asoc_simple_card_unref(struct snd_soc_card *card)
 {
-       struct snd_soc_card *card = platform_get_drvdata(pdev);
        struct snd_soc_dai_link *dai_link;
        struct device_node *np;
        int num_links;
@@ -482,7 +481,7 @@ static int asoc_simple_card_probe(struct platform_device *pdev)
        ret = devm_snd_soc_register_card(&pdev->dev, &priv->snd_card);
 
 err:
-       asoc_simple_card_unref(pdev);
+       asoc_simple_card_unref(&priv->snd_card);
        return ret;
 }