Skip to content

Commit 081da13

Browse files
Heikki Krogerusgregkh
authored andcommitted
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: af8622f ("usb: typec: ucsi: Support for DisplayPort alt mode") Cc: [email protected] Signed-off-by: Heikki Krogerus <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent d16e7b6 commit 081da13

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

drivers/usb/typec/ucsi/displayport.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,8 @@ struct typec_altmode *ucsi_register_displayport(struct ucsi_connector *con,
288288
struct typec_altmode *alt;
289289
struct ucsi_dp *dp;
290290

291+
mutex_lock(&con->lock);
292+
291293
/* We can't rely on the firmware with the capabilities. */
292294
desc->vdo |= DP_CAP_DP_SIGNALING | DP_CAP_RECEPTACLE;
293295

@@ -296,12 +298,15 @@ struct typec_altmode *ucsi_register_displayport(struct ucsi_connector *con,
296298
desc->vdo |= all_assignments << 16;
297299

298300
alt = typec_port_register_altmode(con->port, desc);
299-
if (IS_ERR(alt))
301+
if (IS_ERR(alt)) {
302+
mutex_unlock(&con->lock);
300303
return alt;
304+
}
301305

302306
dp = devm_kzalloc(&alt->dev, sizeof(*dp), GFP_KERNEL);
303307
if (!dp) {
304308
typec_unregister_altmode(alt);
309+
mutex_unlock(&con->lock);
305310
return ERR_PTR(-ENOMEM);
306311
}
307312

@@ -314,5 +319,7 @@ struct typec_altmode *ucsi_register_displayport(struct ucsi_connector *con,
314319
alt->ops = &ucsi_displayport_ops;
315320
typec_altmode_set_drvdata(alt, dp);
316321

322+
mutex_unlock(&con->lock);
323+
317324
return alt;
318325
}

0 commit comments

Comments
 (0)