Skip to contentSkip to conversation

platform/chrome: cros_ec_typec: Check ec platform device pointer

PATCH In review Tomasz Michalec 2 participants 2 messages Jul 22, 2025 – Jul 23, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 platform/chrome: cros_ec_typec: Check ec platform device pointer

It is possible that parent device for cros_ec_typec device is already available, but ec pointer in parent driver data isn't populated yet. It may happen when cros_typec_probe is running in parallel with cros_ec_register. This leads to NULL pointer dereference when cros_typec_probe tries to get driver data from typec->ec->ec->dev.

Check if typec->ec->ec is set before using it in cros_typec_probe.

---
 drivers/platform/chrome/cros_ec_typec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/platform/chrome/cros_ec_typec.c +1 -1
index 7678e3d05fd3..1ef181614d4a 100644
@@ -1271,7 +1271,7 @@ static int cros_typec_probe(struct platform_device *pdev)
 	typec->dev = dev;
 
 	typec->ec = dev_get_drvdata(pdev->dev.parent);
-	if (!typec->ec) {
+	if (!typec->ec || !typec->ec->ec) {
 		dev_err(dev, "couldn't find parent EC device\n");
 		return -ENODEV;
 	}
Signature · 1 line
2.50.0.727.gbf7dc18ff4-goog
maintainer
#1 lore raw
Quoted 9 lines · Tomasz Michalec

It is possible that parent device for cros_ec_typec device is already available, but ec pointer in parent driver data isn't populated yet. It may happen when cros_typec_probe is running in parallel with cros_ec_register. This leads to NULL pointer dereference when cros_typec_probe tries to get driver data from typec->ec->ec->dev.

Check if typec->ec->ec is set before using it in cros_typec_probe.

[...]

Please use at least for-next branch as the commit base next time. I have fixed it this time.

Applied to

https://git.kernel.org/pub/scm/linux/kernel/git/chrome-platform/linux.git for-next

[1/1] platform/chrome: cros_ec_typec: Check ec platform device pointer

      commit: 731a4702b668ef28730e7d2414672b7085e757d6

Thanks!