All of lore.kernel.org
 help / color / mirror / Atom feed
From: Prashant Malani <pmalani@chromium.org>
To: linux-kernel@vger.kernel.org
Cc: heikki.krogerus@linux.intel.com, dzigterman@chromium.org,
	alevkoy@chromium.org, Prashant Malani <pmalani@chromium.org>,
	Benson Leung <bleung@chromium.org>,
	Enric Balletbo i Serra <enric.balletbo@collabora.com>,
	Guenter Roeck <groeck@chromium.org>,
	Mark Brown <broonie@kernel.org>,
	Pi-Hsun Shih <pihsun@chromium.org>
Subject: [PATCH v2 2/7] platform/chrome: cros_ec_typec: Fix remove partner logic
Date: Thu, 29 Oct 2020 15:27:32 -0700	[thread overview]
Message-ID: <20201029222738.482366-3-pmalani@chromium.org> (raw)
In-Reply-To: <20201029222738.482366-1-pmalani@chromium.org>

The cros_unregister_ports() function can be called in situations where
the partner has not been registered yet, and so its related data
structures would not have been initialized. Calling
cros_typec_remove_partner() in such a situation can lead to null pointer
dereferences. So, only call cros_typec_remove_partner() if there is a
valid registered partner pointer.

Signed-off-by: Prashant Malani <pmalani@chromium.org>
---

Changes in v2:
- No changes.

 drivers/platform/chrome/cros_ec_typec.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chrome/cros_ec_typec.c
index 49083e21317d..2665d8125910 100644
--- a/drivers/platform/chrome/cros_ec_typec.c
+++ b/drivers/platform/chrome/cros_ec_typec.c
@@ -190,7 +190,10 @@ static void cros_unregister_ports(struct cros_typec_data *typec)
 	for (i = 0; i < typec->num_ports; i++) {
 		if (!typec->ports[i])
 			continue;
-		cros_typec_remove_partner(typec, i);
+
+		if (typec->ports[i]->partner)
+			cros_typec_remove_partner(typec, i);
+
 		usb_role_switch_put(typec->ports[i]->role_sw);
 		typec_switch_put(typec->ports[i]->ori_sw);
 		typec_mux_put(typec->ports[i]->mux);
-- 
2.29.1.341.ge80a0c044ae-goog


  parent reply	other threads:[~2020-10-29 22:28 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-29 22:27 [PATCH v2 0/7] platform/chrome: cros_ec_typec: Register partner PD information Prashant Malani
2020-10-29 22:27 ` [PATCH v2 1/7] platform/chrome: cros_ec_typec: Relocate set_port_params_v*() functions Prashant Malani
2020-10-29 22:27 ` Prashant Malani [this message]
2020-10-29 22:27 ` [PATCH v2 3/7] platform/chrome: cros_ec_typec: Clear partner identity on device removal Prashant Malani
2020-10-29 22:27 ` [PATCH v2 4/7] platform/chrome: cros_ec: Import Type C host commands Prashant Malani
2020-10-29 22:27 ` [PATCH v2 5/7] platform/chrome: cros_ec_typec: Introduce TYPEC_STATUS Prashant Malani
2020-10-29 22:27 ` [PATCH v2 6/7] platform/chrome: cros_ec_typec: Parse partner PD ID VDOs Prashant Malani
2020-10-30 13:31   ` Heikki Krogerus
2020-10-29 22:27 ` [PATCH v2 7/7] platform/chrome: cros_ec_typec: Register partner altmodes Prashant Malani
2020-10-30 13:32   ` Heikki Krogerus
2020-11-13  8:58 ` [PATCH v2 0/7] platform/chrome: cros_ec_typec: Register partner PD information Enric Balletbo i Serra

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=20201029222738.482366-3-pmalani@chromium.org \
    --to=pmalani@chromium.org \
    --cc=alevkoy@chromium.org \
    --cc=bleung@chromium.org \
    --cc=broonie@kernel.org \
    --cc=dzigterman@chromium.org \
    --cc=enric.balletbo@collabora.com \
    --cc=groeck@chromium.org \
    --cc=heikki.krogerus@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pihsun@chromium.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.