/* Returns 0 for no error, otherwise a negative error code (in which case the enqueue() method must fail). If no error occurs but enqueue() fails anyway, it must call usb_hcd_unlink_urb_from_ep() before releasing the private spinlock and returning.  */
int usb_hcd_link_urb_to_ep(struct usb_hcd *hcd, struct urb *urb)
/* Returns 0 for no error, otherwise a negative error code (in which case the enqueue() method must fail). If no error occurs but enqueue() fails anyway, it must call usb_hcd_unlink_urb_from_ep() before releasing the private spinlock and returning.  */
int usb_hcd_link_urb_to_ep(struct usb_hcd *hcd, struct urb *urb)
{
	int		rc = 0;
	spin_lock(&hcd_urb_list_lock);
	if (unlikely(atomic_read(&urb->reject))) {
		rc = -EPERM;
		goto done;
	}
	if (unlikely(!urb->ep->enabled)) {
		rc = -ENOENT;
		goto done;
	}
	if (unlikely(!urb->dev->can_submit)) {
		rc = -EHOSTUNREACH;
		goto done;
	}
	switch (hcd->state) {
	case HC_STATE_RUNNING:
	case HC_STATE_RESUMING:
		urb->unlinked = 0;
		list_add_tail(&urb->urb_list, &urb->ep->urb_list);
		break;
	default:
		rc = -ESHUTDOWN;
		goto done;
	}
 done:
	spin_unlock(&hcd_urb_list_lock);
	return rc;
}