summaryrefslogtreecommitdiffstats
path: root/drivers/usb
diff options
context:
space:
mode:
authorHans de Goede <hdegoede@redhat.com>2020-07-24 19:46:58 +0200
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2020-07-29 14:11:05 +0200
commit03eafcfb60c0da4f08a638f0dd5926fc2fc1d64a (patch)
treea21cdd10b05959afb57d1bc60610ded798710611 /drivers/usb
parent5f2b8d87bca528616e04344d1fc4032dc5ec0f3d (diff)
downloadlinux-03eafcfb60c0da4f08a638f0dd5926fc2fc1d64a.tar.gz
linux-03eafcfb60c0da4f08a638f0dd5926fc2fc1d64a.tar.bz2
linux-03eafcfb60c0da4f08a638f0dd5926fc2fc1d64a.zip
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>
Diffstat (limited to 'drivers/usb')
-rw-r--r--drivers/usb/typec/tcpm/tcpm.c25
1 files changed, 13 insertions, 12 deletions
diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
index 5fcbab1de40c..b72534393b15 100644
--- a/drivers/usb/typec/tcpm/tcpm.c
+++ b/drivers/usb/typec/tcpm/tcpm.c
@@ -961,6 +961,8 @@ static void tcpm_queue_message(struct tcpm_port *port,
static void tcpm_queue_vdm(struct tcpm_port *port, const u32 header,
const u32 *data, int cnt)
{
+ WARN_ON(!mutex_is_locked(&port->lock));
+
port->vdo_count = cnt + 1;
port->vdo_data[0] = header;
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,
mod_delayed_work(port->wq, &port->vdm_state_machine, 0);
}
+static void tcpm_queue_vdm_unlocked(struct tcpm_port *port, const u32 header,
+ const u32 *data, int cnt)
+{
+ mutex_lock(&port->lock);
+ tcpm_queue_vdm(port, header, data, cnt);
+ mutex_unlock(&port->lock);
+}
+
static void svdm_consume_identity(struct tcpm_port *port, const __le32 *payload,
int cnt)
{
@@ -1508,13 +1518,10 @@ static int tcpm_altmode_enter(struct typec_altmode *altmode, u32 *vdo)
struct tcpm_port *port = typec_altmode_get_drvdata(altmode);
u32 header;
- mutex_lock(&port->lock);
header = VDO(altmode->svid, vdo ? 2 : 1, CMD_ENTER_MODE);
header |= VDO_OPOS(altmode->mode);
- tcpm_queue_vdm(port, header, vdo, vdo ? 1 : 0);
- mutex_unlock(&port->lock);
-
+ tcpm_queue_vdm_unlocked(port, header, vdo, vdo ? 1 : 0);
return 0;
}
@@ -1523,13 +1530,10 @@ static int tcpm_altmode_exit(struct typec_altmode *altmode)
struct tcpm_port *port = typec_altmode_get_drvdata(altmode);
u32 header;
- mutex_lock(&port->lock);
header = VDO(altmode->svid, 1, CMD_EXIT_MODE);
header |= VDO_OPOS(altmode->mode);
- tcpm_queue_vdm(port, header, NULL, 0);
- mutex_unlock(&port->lock);
-
+ tcpm_queue_vdm_unlocked(port, header, NULL, 0);
return 0;
}
@@ -1538,10 +1542,7 @@ static int tcpm_altmode_vdm(struct typec_altmode *altmode,
{
struct tcpm_port *port = typec_altmode_get_drvdata(altmode);
- mutex_lock(&port->lock);
- tcpm_queue_vdm(port, header, data, count - 1);
- mutex_unlock(&port->lock);
-
+ tcpm_queue_vdm_unlocked(port, header, data, count - 1);
return 0;
}