Skip to content

Commit 03eafcf

Browse files
jwrdegoedegregkh
authored andcommitted
usb: typec: tcpm: Add tcpm_queue_vdm_unlocked() helper
Various callers (all the typec_altmode_ops) take the port-lock just for the tcpm_queue_vdm() call. Add a new tcpm_queue_vdm_unlocked() helper which takes the lock, so that its callers don't have to do this themselves. This is a preparation patch for fixing an AB BA lock inversion between the tcpm code and some altmode drivers. Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com> Reviewed-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Hans de Goede <hdegoede@redhat.com> Link: https://lore.kernel.org/r/20200724174702.61754-2-hdegoede@redhat.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 5f2b8d8 commit 03eafcf

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

drivers/usb/typec/tcpm/tcpm.c

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -961,6 +961,8 @@ static void tcpm_queue_message(struct tcpm_port *port,
961961
static void tcpm_queue_vdm(struct tcpm_port *port, const u32 header,
962962
const u32 *data, int cnt)
963963
{
964+
WARN_ON(!mutex_is_locked(&port->lock));
965+
964966
port->vdo_count = cnt + 1;
965967
port->vdo_data[0] = header;
966968
memcpy(&port->vdo_data[1], data, sizeof(u32) * cnt);
@@ -971,6 +973,14 @@ static void tcpm_queue_vdm(struct tcpm_port *port, const u32 header,
971973
mod_delayed_work(port->wq, &port->vdm_state_machine, 0);
972974
}
973975

976+
static void tcpm_queue_vdm_unlocked(struct tcpm_port *port, const u32 header,
977+
const u32 *data, int cnt)
978+
{
979+
mutex_lock(&port->lock);
980+
tcpm_queue_vdm(port, header, data, cnt);
981+
mutex_unlock(&port->lock);
982+
}
983+
974984
static void svdm_consume_identity(struct tcpm_port *port, const __le32 *payload,
975985
int cnt)
976986
{
@@ -1508,13 +1518,10 @@ static int tcpm_altmode_enter(struct typec_altmode *altmode, u32 *vdo)
15081518
struct tcpm_port *port = typec_altmode_get_drvdata(altmode);
15091519
u32 header;
15101520

1511-
mutex_lock(&port->lock);
15121521
header = VDO(altmode->svid, vdo ? 2 : 1, CMD_ENTER_MODE);
15131522
header |= VDO_OPOS(altmode->mode);
15141523

1515-
tcpm_queue_vdm(port, header, vdo, vdo ? 1 : 0);
1516-
mutex_unlock(&port->lock);
1517-
1524+
tcpm_queue_vdm_unlocked(port, header, vdo, vdo ? 1 : 0);
15181525
return 0;
15191526
}
15201527

@@ -1523,13 +1530,10 @@ static int tcpm_altmode_exit(struct typec_altmode *altmode)
15231530
struct tcpm_port *port = typec_altmode_get_drvdata(altmode);
15241531
u32 header;
15251532

1526-
mutex_lock(&port->lock);
15271533
header = VDO(altmode->svid, 1, CMD_EXIT_MODE);
15281534
header |= VDO_OPOS(altmode->mode);
15291535

1530-
tcpm_queue_vdm(port, header, NULL, 0);
1531-
mutex_unlock(&port->lock);
1532-
1536+
tcpm_queue_vdm_unlocked(port, header, NULL, 0);
15331537
return 0;
15341538
}
15351539

@@ -1538,10 +1542,7 @@ static int tcpm_altmode_vdm(struct typec_altmode *altmode,
15381542
{
15391543
struct tcpm_port *port = typec_altmode_get_drvdata(altmode);
15401544

1541-
mutex_lock(&port->lock);
1542-
tcpm_queue_vdm(port, header, data, count - 1);
1543-
mutex_unlock(&port->lock);
1544-
1545+
tcpm_queue_vdm_unlocked(port, header, data, count - 1);
15451546
return 0;
15461547
}
15471548

0 commit comments

Comments
 (0)