Blob Blame History Raw
From a2d6d84db2e7bcc831aed90f33334c70a1b060a3 Mon Sep 17 00:00:00 2001
From: Hans de Goede <hdegoede@redhat.com>
Date: Thu, 6 Jan 2022 12:01:23 +0100
Subject: [PATCH] ASoC: rt5640: Fix possible NULL pointer deref on resume
Git-commit: a2d6d84db2e7bcc831aed90f33334c70a1b060a3
Patch-mainline: v5.17-rc1
References: jsc#PED-850

Commit 2b9c8d2b3c89 ("ASoC: rt5640: Add the HDA header support") adds
re-queuing of the jack_work on resume when rt5640->jd_src != 0.

But the jack_work will unconditionally deref rt5640->jack and that might
be NULL. E.g. the sound/soc/intel/boards/bytcr_rt5640.c machine driver
call snd_soc_component_set_jack(codec, NULL, NULL) from pre_suspend to
disable the IRQ to avoid spurious wakeups, so when rt5640_resume()
runs rt5640->jack will be NULL in this case.

Make the queueing of the work conditional on rt5640->jack instead of
on rt5640->jd_src to fix this.

Fixes: 2b9c8d2b3c89 ("ASoC: rt5640: Add the HDA header support")
Cc: Oder Chiou <oder_chiou@realtek.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Link: https://lore.kernel.org/r/20220106110128.66049-2-hdegoede@redhat.com
Signed-off-by: Mark Brown <broonie@kernel.org>
Acked-by: Takashi Iwai <tiwai@suse.de>

---
 sound/soc/codecs/rt5640.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sound/soc/codecs/rt5640.c b/sound/soc/codecs/rt5640.c
index f3659b14c74e..ceb2d50b17aa 100644
--- a/sound/soc/codecs/rt5640.c
+++ b/sound/soc/codecs/rt5640.c
@@ -2737,7 +2737,7 @@ static int rt5640_resume(struct snd_soc_component *component)
 	regcache_cache_only(rt5640->regmap, false);
 	regcache_sync(rt5640->regmap);
 
-	if (rt5640->jd_src) {
+	if (rt5640->jack) {
 		if (rt5640->jd_src == RT5640_JD_SRC_HDA_HEADER)
 			snd_soc_component_update_bits(component,
 				RT5640_DUMMY2, 0x1100, 0x1100);
-- 
2.35.3