linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Tzung-Bi Shih <tzungbi@kernel.org>
To: Dmitry Torokhov <dmitry.torokhov@gmail.com>,
	Benson Leung <bleung@chromium.org>
Cc: tzungbi@kernel.org, linux-input@vger.kernel.org,
	chrome-platform@lists.linux.dev
Subject: [PATCH 5/5] Input: cros_ec_keyb - Defer probe until parent EC device is registered
Date: Thu, 28 Aug 2025 08:36:01 +0000	[thread overview]
Message-ID: <20250828083601.856083-6-tzungbi@kernel.org> (raw)
In-Reply-To: <20250828083601.856083-1-tzungbi@kernel.org>

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.

Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
---
 drivers/input/keyboard/cros_ec_keyb.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/input/keyboard/cros_ec_keyb.c b/drivers/input/keyboard/cros_ec_keyb.c
index c1e53d87c8a7..f7209c8ebbcc 100644
--- a/drivers/input/keyboard/cros_ec_keyb.c
+++ b/drivers/input/keyboard/cros_ec_keyb.c
@@ -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)
-- 
2.51.0.268.g9569e192d0-goog


  parent reply	other threads:[~2025-08-28  8:36 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-28  8:35 [PATCH 0/5] platform/chrome: Fix a race when probing drivers Tzung-Bi Shih
2025-08-28  8:35 ` [PATCH 1/5] platform/chrome: Centralize cros_ec_device allocation Tzung-Bi Shih
2025-08-28  8:35 ` [PATCH 2/5] platform/chrome: Centralize common cros_ec_device initialization Tzung-Bi Shih
2025-08-28  8:35 ` [PATCH 3/5] platform/chrome: cros_ec: Separate initialization from cros_ec_register() Tzung-Bi Shih
2025-08-28  8:36 ` [PATCH 4/5] platform/chrome: cros_ec: Add a flag to track registration state Tzung-Bi Shih
2025-08-28  8:36 ` Tzung-Bi Shih [this message]
2025-09-14  1:06   ` [PATCH 5/5] Input: cros_ec_keyb - Defer probe until parent EC device is registered Dmitry Torokhov
2025-08-29 11:28 ` [PATCH 0/5] platform/chrome: Fix a race when probing drivers Dmitry Torokhov
2025-08-29 12:50   ` Tzung-Bi Shih
2025-09-02 13:18     ` Tzung-Bi Shih
2025-09-04 14:06       ` Dmitry Torokhov
2025-09-05  8:38         ` Tzung-Bi Shih
2025-09-14  1:08           ` Dmitry Torokhov
2025-09-14  3:26             ` Tzung-Bi Shih
2025-09-14  3:47 ` Tzung-Bi Shih

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250828083601.856083-6-tzungbi@kernel.org \
    --to=tzungbi@kernel.org \
    --cc=bleung@chromium.org \
    --cc=chrome-platform@lists.linux.dev \
    --cc=dmitry.torokhov@gmail.com \
    --cc=linux-input@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).