[PATCH] ASoC: hdac_hda: Fix NULL pointer dereference when hda_pvt is not set

From: Kai-Heng Feng
Date: Tue Dec 12 2023 - 01:45:48 EST


Kernel splat can be found on boot:
[ 7.906438] BUG: kernel NULL pointer dereference, address: 0000000000000078
[ 7.906449] #PF: supervisor read access in kernel mode
[ 7.906455] #PF: error_code(0x0000) - not-present page
[ 7.906461] PGD 0 P4D 0
[ 7.906466] Oops: 0000 [#1] PREEMPT SMP NOPTI
[ 7.906472] CPU: 15 PID: 109 Comm: kworker/15:0 Not tainted 6.7.0-rc5+ #9
[ 7.906480] Hardware name: HP HP ZBook Fury 15 G7 Mobile Workstation/8783, BIOS S92 Ver. 01.15.00 10/03/2023
[ 7.906489] Workqueue: events sof_probe_work [snd_sof]
[ 7.906509] RIP: 0010:hdac_hda_dev_probe+0x48/0x110 [snd_soc_hdac_hda]

This is caused by attempting to dereference hda_pvt, so check if it's
NULL before using it.

Fixes: a0575b4add21 ("ASoC: hdac_hda: Conditionally register dais for HDMI and Analog")
Signed-off-by: Kai-Heng Feng <kai.heng.feng@xxxxxxxxxxxxx>
---
sound/soc/codecs/hdac_hda.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sound/soc/codecs/hdac_hda.c b/sound/soc/codecs/hdac_hda.c
index b075689db2dc..abc214f201a8 100644
--- a/sound/soc/codecs/hdac_hda.c
+++ b/sound/soc/codecs/hdac_hda.c
@@ -632,7 +632,7 @@ static int hdac_hda_dev_probe(struct hdac_device *hdev)
snd_hdac_ext_bus_link_get(hdev->bus, hlink);

/* ASoC specific initialization */
- if (hda_pvt->need_display_power)
+ if (hda_pvt && hda_pvt->need_display_power)
ret = devm_snd_soc_register_component(&hdev->dev,
&hdac_hda_hdmi_codec, hdac_hda_hdmi_dais,
ARRAY_SIZE(hdac_hda_hdmi_dais));
--
2.34.1