Commit 87e44f2a authored by Lu Baolu's avatar Lu Baolu Committed by Greg Kroah-Hartman

usb: xhci: remove the use of xhci->addr_dev

xhci->addr_dev is used for the completion of both address device
and enable slot commands. It's shared by enumerations of all USB
devices connected to an xhci host. Hence, it's just a source for
possible races. Since we've introduced command structure and the
command queue to xhci driver.  It is time to get rid of addr_dev
and use the completion in the command structure instead.
Signed-off-by: default avatarLu Baolu <baolu.lu@linux.intel.com>
Signed-off-by: default avatarMathias Nyman <mathias.nyman@linux.intel.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 228cfaea
...@@ -2535,7 +2535,6 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags) ...@@ -2535,7 +2535,6 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags)
* something other than the default (~1ms minimum between interrupts). * something other than the default (~1ms minimum between interrupts).
* See section 5.5.1.2. * See section 5.5.1.2.
*/ */
init_completion(&xhci->addr_dev);
for (i = 0; i < MAX_HC_SLOTS; ++i) for (i = 0; i < MAX_HC_SLOTS; ++i)
xhci->devs[i] = NULL; xhci->devs[i] = NULL;
for (i = 0; i < USB_MAXCHILDREN; ++i) { for (i = 0; i < USB_MAXCHILDREN; ++i) {
......
...@@ -3687,20 +3687,19 @@ int xhci_alloc_dev(struct usb_hcd *hcd, struct usb_device *udev) ...@@ -3687,20 +3687,19 @@ int xhci_alloc_dev(struct usb_hcd *hcd, struct usb_device *udev)
int ret, slot_id; int ret, slot_id;
struct xhci_command *command; struct xhci_command *command;
command = xhci_alloc_command(xhci, false, false, GFP_KERNEL); command = xhci_alloc_command(xhci, false, true, GFP_KERNEL);
if (!command) if (!command)
return 0; return 0;
/* xhci->slot_id and xhci->addr_dev are not thread-safe */ /* xhci->slot_id and xhci->addr_dev are not thread-safe */
mutex_lock(&xhci->mutex); mutex_lock(&xhci->mutex);
spin_lock_irqsave(&xhci->lock, flags); spin_lock_irqsave(&xhci->lock, flags);
command->completion = &xhci->addr_dev;
ret = xhci_queue_slot_control(xhci, command, TRB_ENABLE_SLOT, 0); ret = xhci_queue_slot_control(xhci, command, TRB_ENABLE_SLOT, 0);
if (ret) { if (ret) {
spin_unlock_irqrestore(&xhci->lock, flags); spin_unlock_irqrestore(&xhci->lock, flags);
mutex_unlock(&xhci->mutex); mutex_unlock(&xhci->mutex);
xhci_dbg(xhci, "FIXME: allocate a command ring segment\n"); xhci_dbg(xhci, "FIXME: allocate a command ring segment\n");
kfree(command); xhci_free_command(xhci, command);
return 0; return 0;
} }
xhci_ring_cmd_db(xhci); xhci_ring_cmd_db(xhci);
...@@ -3715,7 +3714,7 @@ int xhci_alloc_dev(struct usb_hcd *hcd, struct usb_device *udev) ...@@ -3715,7 +3714,7 @@ int xhci_alloc_dev(struct usb_hcd *hcd, struct usb_device *udev)
xhci_err(xhci, "Max number of devices this xHCI host supports is %u.\n", xhci_err(xhci, "Max number of devices this xHCI host supports is %u.\n",
HCS_MAX_SLOTS( HCS_MAX_SLOTS(
readl(&xhci->cap_regs->hcs_params1))); readl(&xhci->cap_regs->hcs_params1)));
kfree(command); xhci_free_command(xhci, command);
return 0; return 0;
} }
...@@ -3751,7 +3750,7 @@ int xhci_alloc_dev(struct usb_hcd *hcd, struct usb_device *udev) ...@@ -3751,7 +3750,7 @@ int xhci_alloc_dev(struct usb_hcd *hcd, struct usb_device *udev)
#endif #endif
kfree(command); xhci_free_command(xhci, command);
/* Is this a LS or FS device under a HS hub? */ /* Is this a LS or FS device under a HS hub? */
/* Hub or peripherial? */ /* Hub or peripherial? */
return 1; return 1;
...@@ -3759,6 +3758,7 @@ int xhci_alloc_dev(struct usb_hcd *hcd, struct usb_device *udev) ...@@ -3759,6 +3758,7 @@ int xhci_alloc_dev(struct usb_hcd *hcd, struct usb_device *udev)
disable_slot: disable_slot:
/* Disable slot, if we can do it without mem alloc */ /* Disable slot, if we can do it without mem alloc */
spin_lock_irqsave(&xhci->lock, flags); spin_lock_irqsave(&xhci->lock, flags);
kfree(command->completion);
command->completion = NULL; command->completion = NULL;
command->status = 0; command->status = 0;
if (!xhci_queue_slot_control(xhci, command, TRB_DISABLE_SLOT, if (!xhci_queue_slot_control(xhci, command, TRB_DISABLE_SLOT,
...@@ -3820,14 +3820,13 @@ static int xhci_setup_device(struct usb_hcd *hcd, struct usb_device *udev, ...@@ -3820,14 +3820,13 @@ static int xhci_setup_device(struct usb_hcd *hcd, struct usb_device *udev,
} }
} }
command = xhci_alloc_command(xhci, false, false, GFP_KERNEL); command = xhci_alloc_command(xhci, false, true, GFP_KERNEL);
if (!command) { if (!command) {
ret = -ENOMEM; ret = -ENOMEM;
goto out; goto out;
} }
command->in_ctx = virt_dev->in_ctx; command->in_ctx = virt_dev->in_ctx;
command->completion = &xhci->addr_dev;
slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->in_ctx); slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->in_ctx);
ctrl_ctx = xhci_get_input_control_ctx(virt_dev->in_ctx); ctrl_ctx = xhci_get_input_control_ctx(virt_dev->in_ctx);
...@@ -3945,7 +3944,10 @@ static int xhci_setup_device(struct usb_hcd *hcd, struct usb_device *udev, ...@@ -3945,7 +3944,10 @@ static int xhci_setup_device(struct usb_hcd *hcd, struct usb_device *udev,
le32_to_cpu(slot_ctx->dev_state) & DEV_ADDR_MASK); le32_to_cpu(slot_ctx->dev_state) & DEV_ADDR_MASK);
out: out:
mutex_unlock(&xhci->mutex); mutex_unlock(&xhci->mutex);
kfree(command); if (command) {
kfree(command->completion);
kfree(command);
}
return ret; return ret;
} }
......
...@@ -1584,7 +1584,6 @@ struct xhci_hcd { ...@@ -1584,7 +1584,6 @@ struct xhci_hcd {
/* slot enabling and address device helpers */ /* slot enabling and address device helpers */
/* these are not thread safe so use mutex */ /* these are not thread safe so use mutex */
struct mutex mutex; struct mutex mutex;
struct completion addr_dev;
int slot_id; int slot_id;
/* For USB 3.0 LPM enable/disable. */ /* For USB 3.0 LPM enable/disable. */
struct xhci_command *lpm_command; struct xhci_command *lpm_command;
......
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