diff mbox series

soundwire: intel_init: test link->cdns

Message ID 20210331010250.14151-1-yung-chuan.liao@linux.intel.com
State Superseded
Headers show
Series soundwire: intel_init: test link->cdns | expand

Commit Message

Liao, Bard March 31, 2021, 1:02 a.m. UTC
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.

Signed-off-by: Bard Liao <yung-chuan.liao@linux.intel.com>
Reviewed-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Reviewed-by: Rander Wang <rander.wang@intel.com>
Reviewed-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
---
 drivers/soundwire/intel_init.c | 9 +++++++++
 1 file changed, 9 insertions(+)

Comments

Vinod Koul April 1, 2021, 7:21 a.m. UTC | #1
On 31-03-21, 09:02, Bard Liao wrote:
> 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
Pierre-Louis Bossart April 1, 2021, 2:31 p.m. UTC | #2
On 4/1/21 2:21 AM, Vinod Koul wrote:
> On 31-03-21, 09:02, Bard Liao wrote:
>> 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?
diff mbox series

Patch

diff --git a/drivers/soundwire/intel_init.c b/drivers/soundwire/intel_init.c
index 5b32a2ffd376..5ef5bd0defab 100644
--- a/drivers/soundwire/intel_init.c
+++ b/drivers/soundwire/intel_init.c
@@ -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 */