| From 085624b7b2edbb15ccba15437b5affc400adc1b0 Mon Sep 17 00:00:00 2001 |
| From: Lu Baolu <baolu.lu@linux.intel.com> |
| Date: Fri, 11 Nov 2016 15:13:31 +0200 |
| Subject: [PATCH 293/299] usb: xhci: move slot_id from xhci_hcd to xhci_command |
| structure |
| |
| xhci->slot_id is used for providing a way to pass slot id from the |
| command completion handler to the function waiting for completion. |
| It's shared by enumerations of all USB devices connected to an |
| xhci host. Hence, it's a source for possible races. Since we've |
| introduced command structure and the command queue to xhci driver. |
| It's better to move slot_id from xhci_hcd structure to xhci_command |
| structure. Hence the race source is removed. |
| |
| Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com> |
| Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com> |
| Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> |
| (cherry picked from commit c2d3d49bba0889f42e4753651d103f7ba74fbaf1) |
| Signed-off-by: Simon Horman <horms+renesas@verge.net.au> |
| --- |
| drivers/usb/host/xhci-ring.c | 8 ++++---- |
| drivers/usb/host/xhci.c | 2 +- |
| drivers/usb/host/xhci.h | 2 +- |
| 3 files changed, 6 insertions(+), 6 deletions(-) |
| |
| --- a/drivers/usb/host/xhci-ring.c |
| +++ b/drivers/usb/host/xhci-ring.c |
| @@ -1151,12 +1151,12 @@ static void xhci_handle_cmd_reset_ep(str |
| } |
| |
| static void xhci_handle_cmd_enable_slot(struct xhci_hcd *xhci, int slot_id, |
| - u32 cmd_comp_code) |
| + struct xhci_command *command, u32 cmd_comp_code) |
| { |
| if (cmd_comp_code == COMP_SUCCESS) |
| - xhci->slot_id = slot_id; |
| + command->slot_id = slot_id; |
| else |
| - xhci->slot_id = 0; |
| + command->slot_id = 0; |
| } |
| |
| static void xhci_handle_cmd_disable_slot(struct xhci_hcd *xhci, int slot_id) |
| @@ -1389,7 +1389,7 @@ static void handle_cmd_completion(struct |
| cmd_type = TRB_FIELD_TO_TYPE(le32_to_cpu(cmd_trb->generic.field[3])); |
| switch (cmd_type) { |
| case TRB_ENABLE_SLOT: |
| - xhci_handle_cmd_enable_slot(xhci, slot_id, cmd_comp_code); |
| + xhci_handle_cmd_enable_slot(xhci, slot_id, cmd, cmd_comp_code); |
| break; |
| case TRB_DISABLE_SLOT: |
| xhci_handle_cmd_disable_slot(xhci, slot_id); |
| --- a/drivers/usb/host/xhci.c |
| +++ b/drivers/usb/host/xhci.c |
| @@ -3699,7 +3699,7 @@ int xhci_alloc_dev(struct usb_hcd *hcd, |
| spin_unlock_irqrestore(&xhci->lock, flags); |
| |
| wait_for_completion(command->completion); |
| - slot_id = xhci->slot_id; |
| + slot_id = command->slot_id; |
| mutex_unlock(&xhci->mutex); |
| |
| if (!slot_id || command->status != COMP_SUCCESS) { |
| --- a/drivers/usb/host/xhci.h |
| +++ b/drivers/usb/host/xhci.h |
| @@ -786,6 +786,7 @@ struct xhci_command { |
| /* Input context for changing device state */ |
| struct xhci_container_ctx *in_ctx; |
| u32 status; |
| + int slot_id; |
| /* If completion is null, no one is waiting on this command |
| * and the structure can be freed after the command completes. |
| */ |
| @@ -1580,7 +1581,6 @@ struct xhci_hcd { |
| /* slot enabling and address device helpers */ |
| /* these are not thread safe so use mutex */ |
| struct mutex mutex; |
| - int slot_id; |
| /* For USB 3.0 LPM enable/disable. */ |
| struct xhci_command *lpm_command; |
| /* Internal mirror of the HW's dcbaa */ |