From 567bcd3b7a4abb1daf4c7490be498b5d0705511f Mon Sep 17 00:00:00 2001 From: Meng Wang Date: Tue, 18 Sep 2018 09:47:06 +0800 Subject: [PATCH] ASoC: wcd934x: check sound card state to avoid pointer dereference When codec probe is not correctly completed and ADSP SSR happens before sound card is registered, calling SSR callback may result into NULL pointer dereference and kernel panic happens. Check sound card state when calling device_down and post_reset to avoid NULL pointer dereference. Change-Id: I35fd84af51edf45db6fd451dc68dbcaaed11fee7 Signed-off-by: Meng Wang --- asoc/codecs/wcd934x/wcd934x.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/asoc/codecs/wcd934x/wcd934x.c b/asoc/codecs/wcd934x/wcd934x.c index 49c17c41e4..36676767fb 100644 --- a/asoc/codecs/wcd934x/wcd934x.c +++ b/asoc/codecs/wcd934x/wcd934x.c @@ -9977,6 +9977,12 @@ static int tavil_device_down(struct wcd9xxx *wcd9xxx) int ret; codec = (struct snd_soc_codec *)(wcd9xxx->ssr_priv); + if (!codec->component.card) { + dev_err(codec->dev, "%s: sound card is not enumerated.\n", + __func__); + return -EINVAL; + } + priv = snd_soc_codec_get_drvdata(codec); for (count = 0; count < NUM_CODEC_DAIS; count++) priv->dai[count].bus_down_in_recovery = true; @@ -10027,6 +10033,11 @@ static int tavil_post_reset_cb(struct wcd9xxx *wcd9xxx) struct wcd_mbhc *mbhc; codec = (struct snd_soc_codec *)(wcd9xxx->ssr_priv); + if (!codec->component.card) { + dev_err(codec->dev, "%s: sound card is not enumerated.\n", + __func__); + return -EINVAL; + } tavil = snd_soc_codec_get_drvdata(codec); control = dev_get_drvdata(codec->dev->parent);