From e672f430ead50510b4db7986b19ae4d10a3e6aea Mon Sep 17 00:00:00 2001 From: Libin Yang Date: Mon, 7 Jan 2019 16:13:30 +0800 Subject: [PATCH] ASoC: sof: add check of NULL in suspend/resume If sof driver fails to initialize, sdev (or priv) may be NULL. The sanity check of NULL is necessary. Signed-off-by: Libin Yang --- sound/soc/sof/pm.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/sound/soc/sof/pm.c b/sound/soc/sof/pm.c index 46efffc85ea3a1..f94d8cdb233915 100644 --- a/sound/soc/sof/pm.c +++ b/sound/soc/sof/pm.c @@ -232,6 +232,9 @@ static int sof_resume(struct device *dev, bool runtime_resume) struct snd_sof_dev *sdev = dev_get_drvdata(&priv->pdev_pcm->dev); int ret = 0; + if (!sdev) + return 0; + /* do nothing if dsp resume callbacks are not set */ if (!sof_ops(sdev)->resume || !sof_ops(sdev)->runtime_resume) return 0; @@ -302,6 +305,16 @@ static int sof_suspend(struct device *dev, bool runtime_suspend) struct snd_sof_dev *sdev = dev_get_drvdata(&priv->pdev_pcm->dev); int ret = 0; + /* + * If sdev is NULL, it meams the sof audio driver fails in + * initialization. Let's return 0 to let suspend/resume + * be successful. The audio system should already be powered down + * if the probe step if initialization fails. The same with resume() + * and prepare() callback. + */ + if (!sdev) + return 0; + /* do nothing if dsp suspend callback is not set */ if (!sof_ops(sdev)->suspend) return 0; @@ -379,6 +392,9 @@ int snd_sof_prepare(struct device *dev) struct sof_platform_priv *priv = dev_get_drvdata(dev); struct snd_sof_dev *sdev = dev_get_drvdata(&priv->pdev_pcm->dev); + if (!sdev) + return 0; + /* * PCI devices are brought back to full power before system suspend. * Setting this flag will prevent restoring kcontrols