Skip to contentSkip to conversation

ucsi driver fixes for usb-linus

PATCH New Heikki Krogerus 1 participant 3 messages Mar 11, 2020

Subsystems (3)
lore
Share & tools
lore

Heikki Krogerus

author maintainer
#0 lore raw

cover ucsi driver fixes for usb-linus

Heikki Krogerus (2):
usb: typec: ucsi: displayport: Fix NULL pointer dereference
usb: typec: ucsi: displayport: Fix a potential race during
registration

 drivers/usb/typec/ucsi/displayport.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
Signature · 1 line
2.25.1
author maintainer
#1 lore raw

PATCH 1/2 usb: typec: ucsi: displayport: Fix NULL pointer dereference

If the registration of the DisplayPort was not successful, or if the port does not support DisplayPort alt mode in the first place, the function ucsi_displayport_remove_partner() will fail with NULL pointer dereference when it attempts to access the driver data.

Adding a check to the function to make sure there really is driver data for the device before modifying it.

Fixes af8622f6a585 ("usb: typec: ucsi: Support for DisplayPort alt mode")
---
 drivers/usb/typec/ucsi/displayport.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/usb/typec/ucsi/displayport.c +3 -0
index 0f1273ae086c..261131c9e37c 100644
@@ -271,6 +271,9 @@ void ucsi_displayport_remove_partner(struct typec_altmode *alt)
 		return;
 
 	dp = typec_altmode_get_drvdata(alt);
+	if (!dp)
+		return;
+
 	dp->data.conf = 0;
 	dp->data.status = 0;
 	dp->initialized = false;
Signature · 1 line
2.25.1
author maintainer
#2 lore raw

PATCH 2/2 usb: typec: ucsi: displayport: Fix a potential race during registration

In reply to Heikki Krogerus

Locking the connector in ucsi_register_displayport() to make sure that nothing can access the displayport alternate mode before the function has finished and the alternate mode is actually ready.

Fixes af8622f6a585 ("usb: typec: ucsi: Support for DisplayPort alt mode")
---
 drivers/usb/typec/ucsi/displayport.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/usb/typec/ucsi/displayport.c +8 -1
index 261131c9e37c..048381c058a5 100644
@@ -288,6 +288,8 @@ struct typec_altmode *ucsi_register_displayport(struct ucsi_connector *con,
 	struct typec_altmode *alt;
 	struct ucsi_dp *dp;
 
+	mutex_lock(&con->lock);
+
 	/* We can't rely on the firmware with the capabilities. */
 	desc->vdo |= DP_CAP_DP_SIGNALING | DP_CAP_RECEPTACLE;
 
@@ -296,12 +298,15 @@ struct typec_altmode *ucsi_register_displayport(struct ucsi_connector *con,
 	desc->vdo |= all_assignments << 16;
 
 	alt = typec_port_register_altmode(con->port, desc);
-	if (IS_ERR(alt))
+	if (IS_ERR(alt)) {
+		mutex_unlock(&con->lock);
 		return alt;
+	}
 
 	dp = devm_kzalloc(&alt->dev, sizeof(*dp), GFP_KERNEL);
 	if (!dp) {
 		typec_unregister_altmode(alt);
+		mutex_unlock(&con->lock);
 		return ERR_PTR(-ENOMEM);
 	}
 
@@ -314,5 +319,7 @@ struct typec_altmode *ucsi_register_displayport(struct ucsi_connector *con,
 	alt->ops = &ucsi_displayport_ops;
 	typec_altmode_set_drvdata(alt, dp);
 
+	mutex_unlock(&con->lock);
+
 	return alt;
 }
Signature · 1 line
2.25.1