]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
Input: cros_ec_keyb - Defer probe until parent EC device is registered
authorTzung-Bi Shih <tzungbi@kernel.org>
Thu, 28 Aug 2025 08:36:01 +0000 (08:36 +0000)
committerTzung-Bi Shih <tzungbi@kernel.org>
Sun, 14 Sep 2025 03:34:41 +0000 (11:34 +0800)
The `cros_ec_keyb` driver can be probed before the cros_ec_device has
completed the registration.  This creates a race condition where
`cros_ec_keyb` might access uninitialized data.

Fix this by calling `cros_ec_device_registered()` to check the parent's
status.  If the device is not yet ready, return -EPROBE_DEFER to ensure
the probe is retried later.

Acked-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Link: https://lore.kernel.org/r/20250828083601.856083-6-tzungbi@kernel.org
Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
drivers/input/keyboard/cros_ec_keyb.c

index c1e53d87c8a759157ed267253ca2f942f36efd2a..f7209c8ebbccd146e1f14e5f8a10a5b99f28cc81 100644 (file)
@@ -705,6 +705,12 @@ static int cros_ec_keyb_probe(struct platform_device *pdev)
        ec = dev_get_drvdata(pdev->dev.parent);
        if (!ec)
                return -EPROBE_DEFER;
+       /*
+        * Even if the cros_ec_device pointer is available, still need to check
+        * if the device is fully registered before using it.
+        */
+       if (!cros_ec_device_registered(ec))
+               return -EPROBE_DEFER;
 
        ckdev = devm_kzalloc(dev, sizeof(*ckdev), GFP_KERNEL);
        if (!ckdev)