Commit 081da132 authored by Heikki Krogerus's avatar Heikki Krogerus Committed by Greg Kroah-Hartman

usb: typec: ucsi: displayport: Fix a potential race during registration

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: af8622f6 ("usb: typec: ucsi: Support for DisplayPort alt mode")
Cc: stable@vger.kernel.org
Signed-off-by: default avatarHeikki Krogerus <heikki.krogerus@linux.intel.com>
Link: https://lore.kernel.org/r/20200311130006.41288-3-heikki.krogerus@linux.intel.comSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent d16e7b62
...@@ -288,6 +288,8 @@ struct typec_altmode *ucsi_register_displayport(struct ucsi_connector *con, ...@@ -288,6 +288,8 @@ struct typec_altmode *ucsi_register_displayport(struct ucsi_connector *con,
struct typec_altmode *alt; struct typec_altmode *alt;
struct ucsi_dp *dp; struct ucsi_dp *dp;
mutex_lock(&con->lock);
/* We can't rely on the firmware with the capabilities. */ /* We can't rely on the firmware with the capabilities. */
desc->vdo |= DP_CAP_DP_SIGNALING | DP_CAP_RECEPTACLE; desc->vdo |= DP_CAP_DP_SIGNALING | DP_CAP_RECEPTACLE;
...@@ -296,12 +298,15 @@ struct typec_altmode *ucsi_register_displayport(struct ucsi_connector *con, ...@@ -296,12 +298,15 @@ struct typec_altmode *ucsi_register_displayport(struct ucsi_connector *con,
desc->vdo |= all_assignments << 16; desc->vdo |= all_assignments << 16;
alt = typec_port_register_altmode(con->port, desc); alt = typec_port_register_altmode(con->port, desc);
if (IS_ERR(alt)) if (IS_ERR(alt)) {
mutex_unlock(&con->lock);
return alt; return alt;
}
dp = devm_kzalloc(&alt->dev, sizeof(*dp), GFP_KERNEL); dp = devm_kzalloc(&alt->dev, sizeof(*dp), GFP_KERNEL);
if (!dp) { if (!dp) {
typec_unregister_altmode(alt); typec_unregister_altmode(alt);
mutex_unlock(&con->lock);
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
} }
...@@ -314,5 +319,7 @@ struct typec_altmode *ucsi_register_displayport(struct ucsi_connector *con, ...@@ -314,5 +319,7 @@ struct typec_altmode *ucsi_register_displayport(struct ucsi_connector *con,
alt->ops = &ucsi_displayport_ops; alt->ops = &ucsi_displayport_ops;
typec_altmode_set_drvdata(alt, dp); typec_altmode_set_drvdata(alt, dp);
mutex_unlock(&con->lock);
return alt; return alt;
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment