public inbox for chrome-platform@lists.linux.dev
 help / color / mirror / Atom feed
From: Tomasz Michalec <tmichalec@google.com>
To: Benson Leung <bleung@chromium.org>,
	 Abhishek Pandit-Subedi <abhishekpandit@chromium.org>,
	Jameson Thies <jthies@google.com>,
	 Andrei Kuchynski <akuchynski@chromium.org>,
	Tzung-Bi Shih <tzungbi@kernel.org>
Cc: Guenter Roeck <groeck@chromium.org>,
	Konrad Adamczyk <konrada@google.com>,
	 chrome-platform@lists.linux.dev, linux-kernel@vger.kernel.org,
	 chromeos-krk-upstreaming@google.com,
	Tomasz Michalec <tmichalec@google.com>
Subject: [PATCH] platform/chrome: cros_ec_typec: Check ec platform device pointer
Date: Tue, 22 Jul 2025 15:28:26 +0200	[thread overview]
Message-ID: <20250722132826.707087-1-tmichalec@google.com> (raw)

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>
---
 drivers/platform/chrome/cros_ec_typec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chrome/cros_ec_typec.c
index 7678e3d05fd3..1ef181614d4a 100644
--- a/drivers/platform/chrome/cros_ec_typec.c
+++ b/drivers/platform/chrome/cros_ec_typec.c
@@ -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;
 	}
-- 
2.50.0.727.gbf7dc18ff4-goog


             reply	other threads:[~2025-07-22 13:28 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-22 13:28 Tomasz Michalec [this message]
2025-07-23  3:24 ` [PATCH] platform/chrome: cros_ec_typec: Check ec platform device pointer 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=20250722132826.707087-1-tmichalec@google.com \
    --to=tmichalec@google.com \
    --cc=abhishekpandit@chromium.org \
    --cc=akuchynski@chromium.org \
    --cc=bleung@chromium.org \
    --cc=chrome-platform@lists.linux.dev \
    --cc=chromeos-krk-upstreaming@google.com \
    --cc=groeck@chromium.org \
    --cc=jthies@google.com \
    --cc=konrada@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tzungbi@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