All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] usb: typec: ucsi: Only check the contract if there is a connection
@ 2021-12-17 14:03 Heikki Krogerus
  2021-12-17 14:32 ` Thorsten Leemhuis
  0 siblings, 1 reply; 10+ messages in thread
From: Heikki Krogerus @ 2021-12-17 14:03 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: Thorsten Leemhuis, linux-usb

The driver must make sure there is an actual connection
before checking details about the USB Power Delivery
contract. Those details are not valid unless there is a
connection.

This fixes NULL pointer dereference that is caused by an
attempt to register bogus partner alternate mode that the
firmware on some platform may report before the actual
connection.

Fixes: 6cbe4b2d5a3f ("usb: typec: ucsi: Check the partner alt modes always if there is PD contract")
BugLink: https://bugzilla.kernel.org/show_bug.cgi?id=215117
Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
---
 drivers/usb/typec/ucsi/ucsi.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c
index 9d6b7e02d6efb..f0c2fa19f3e0f 100644
--- a/drivers/usb/typec/ucsi/ucsi.c
+++ b/drivers/usb/typec/ucsi/ucsi.c
@@ -1164,7 +1164,9 @@ static int ucsi_register_port(struct ucsi *ucsi, int index)
 		ret = 0;
 	}
 
-	if (UCSI_CONSTAT_PWR_OPMODE(con->status.flags) == UCSI_CONSTAT_PWR_OPMODE_PD) {
+	if (con->partner &&
+	    UCSI_CONSTAT_PWR_OPMODE(con->status.flags) ==
+	    UCSI_CONSTAT_PWR_OPMODE_PD) {
 		ucsi_get_src_pdos(con);
 		ucsi_check_altmodes(con);
 	}
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2021-12-21  7:17 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-12-17 14:03 [PATCH] usb: typec: ucsi: Only check the contract if there is a connection Heikki Krogerus
2021-12-17 14:32 ` Thorsten Leemhuis
2021-12-17 15:14   ` Heikki Krogerus
2021-12-17 17:25     ` Thorsten Leemhuis
2021-12-20 15:38       ` Heikki Krogerus
2021-12-17 21:45     ` Chris Hixon
2021-12-20 14:47     ` Greg Kroah-Hartman
2021-12-20 15:41       ` Heikki Krogerus
2021-12-20 16:55         ` Greg Kroah-Hartman
2021-12-21  7:17           ` Heikki Krogerus

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.