Skip to contentSkip to conversation

soundwire: intel_init: test link->cdns

PATCH Superseded Bard Liao 3 participants 3 messages Mar 31, 2021 – Apr 1, 2021 SoundWire

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Bard Liao

author maintainer
#0 lore raw

PATCH 1/1 soundwire: intel_init: test link->cdns

intel_link_probe() could return error and dev_get_drvdata() will return null in such case. So we have to test link->cdns after link->cdns = dev_get_drvdata(&ldev->auxdev.dev);
Otherwise, we will meet the "kernel NULL pointer dereference" error.

---
 drivers/soundwire/intel_init.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/soundwire/intel_init.c +9 -0
index 5b32a2ffd376..5ef5bd0defab 100644
@@ -250,6 +250,15 @@ static struct sdw_intel_ctx
 		link = &ldev->link_res;
 		link->cdns = dev_get_drvdata(&ldev->auxdev.dev);
 
+		if (!link->cdns) {
+			dev_err(&adev->dev, "failed to get link->cdns\n");
+			/*
+			 * 1 will be subtracted from i in the err label, but we need to call
+			 * intel_link_dev_unregister for this ldev, so plus 1 now
+			 */
+			i++;
+			goto err;
+		}
 		list_add_tail(&link->list, &ctx->link_list);
 		bus = &link->cdns->bus;
 		/* Calculate number of slaves */
Signature · 1 line
2.17.1
maintainer
#1 lore raw
Quoted 4 lines · Bard Liao

intel_link_probe() could return error and dev_get_drvdata() will return null in such case. So we have to test link->cdns after link->cdns = dev_get_drvdata(&ldev->auxdev.dev);
Otherwise, we will meet the "kernel NULL pointer dereference" error.

This fails to apply for me

Signature · 1 line
~Vinod
#2 lore raw
Quoted 7 lines · Vinod Koul
Quoted 4 lines · Bard Liao

intel_link_probe() could return error and dev_get_drvdata() will return null in such case. So we have to test link->cdns after link->cdns = dev_get_drvdata(&ldev->auxdev.dev);
Otherwise, we will meet the "kernel NULL pointer dereference" error.

This fails to apply for me

probably a dependency on the auxiliary bus transition?