linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mathias Nyman <mathias.nyman@linux.intel.com>
To: Felipe Balbi <felipe.balbi@linux.intel.com>
Cc: Linux USB <linux-usb@vger.kernel.org>
Subject: [02/20] usb: host: xhci: check DYING state earlier
Date: Mon, 16 Apr 2018 16:31:30 +0300	[thread overview]
Message-ID: <6375ffbc-8ade-6d32-cda1-26cc636e9719@linux.intel.com> (raw)

On 16.04.2018 15:29, Felipe Balbi wrote:
> Instead of allocating urb priv and, maybe, bail out due to xhci being
> in DYING state, we can move the check earlier and avoid the memory
> allocation altogether.

This also moves checking for DYING outside the lock.

Most cases set DYING with lock held, so if we first get the lock before
checking DYING we have a better chance of not being in the process of dying.

Small thing, but so is this cleanup, so not sure its worth the change

-Mathias

> 
> While at that, also remove an unnecessary empty line.
> 
> Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
> ---
>   drivers/usb/host/xhci.c | 13 ++++++-------
>   1 file changed, 6 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
> index 65c454b94165..39e67b7bece1 100644
> --- a/drivers/usb/host/xhci.c
> +++ b/drivers/usb/host/xhci.c
> @@ -1299,6 +1299,12 @@ static int xhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, gfp_t mem_flag
>   					true, true, __func__) <= 0)
>   		return -EINVAL;
>   
> +	if (xhci->xhc_state & XHCI_STATE_DYING) {
> +		xhci_dbg(xhci, "Ep 0x%x: URB %p submitted for non-responsive xHCI host.\n",
> +			 urb->ep->desc.bEndpointAddress, urb);
> +		return -ESHUTDOWN;
> +	}
> +
>   	slot_id = urb->dev->slot_id;
>   	ep_index = xhci_get_endpoint_index(&urb->ep->desc);
>   	ep_state = &xhci->devs[slot_id]->eps[ep_index].ep_state;
> @@ -1347,12 +1353,6 @@ static int xhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, gfp_t mem_flag
>   
>   	spin_lock_irqsave(&xhci->lock, flags);
>   
> -	if (xhci->xhc_state & XHCI_STATE_DYING) {
> -		xhci_dbg(xhci, "Ep 0x%x: URB %p submitted for non-responsive xHCI host.\n",
> -			 urb->ep->desc.bEndpointAddress, urb);
> -		ret = -ESHUTDOWN;
> -		goto free_priv;
> -	}
>   	if (*ep_state & EP_SOFT_CLEAR_TOGGLE) {
>   		xhci_warn(xhci, "Can't enqueue URB while manually clearing toggle\n");
>   		ret = -EINVAL;
> @@ -1360,7 +1360,6 @@ static int xhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, gfp_t mem_flag
>   	}
>   
>   	switch (usb_endpoint_type(&urb->ep->desc)) {
> -
>   	case USB_ENDPOINT_XFER_CONTROL:
>   		ret = xhci_queue_ctrl_tx(xhci, GFP_ATOMIC, urb,
>   					 slot_id, ep_index);
>
---
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

             reply	other threads:[~2018-04-16 13:31 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-16 13:31 Mathias Nyman [this message]
  -- strict thread matches above, loose matches on Subject: below --
2018-05-02 14:11 [02/20] usb: host: xhci: check DYING state earlier Alan Stern
2018-05-02 13:02 Mathias Nyman
2018-05-02 11:46 Felipe Balbi
2018-05-02 11:38 Mathias Nyman
2018-04-17  7:07 Felipe Balbi
2018-04-16 12:29 Felipe Balbi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6375ffbc-8ade-6d32-cda1-26cc636e9719@linux.intel.com \
    --to=mathias.nyman@linux.intel.com \
    --cc=felipe.balbi@linux.intel.com \
    --cc=linux-usb@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).