]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
platform/chrome: cros_ec_typec: Check ec platform device pointer
authorTomasz Michalec <tmichalec@google.com>
Tue, 22 Jul 2025 13:28:26 +0000 (15:28 +0200)
committerTzung-Bi Shih <tzungbi@kernel.org>
Wed, 23 Jul 2025 03:19:16 +0000 (03:19 +0000)
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.

Signed-off-by: Tomasz Michalec <tmichalec@google.com>
Link: https://lore.kernel.org/r/20250722132826.707087-1-tmichalec@google.com
Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
drivers/platform/chrome/cros_ec_typec.c

index 5a141401e4857d771a57cb3c755540a1a5cc69a2..b712bcff6fb2674ec79286159090df6d79b32e9a 100644 (file)
@@ -1354,7 +1354,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_warn(dev, "couldn't find parent EC device\n");
                return -EPROBE_DEFER;
        }