aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'drivers')
-rw-r--r--drivers/usb/core/urb.c70
1 files changed, 70 insertions, 0 deletions
diff --git a/drivers/usb/core/urb.c b/drivers/usb/core/urb.c
index eebc070c3cc7..175d528f4029 100644
--- a/drivers/usb/core/urb.c
+++ b/drivers/usb/core/urb.c
@@ -716,3 +716,73 @@ int usb_wait_anchor_empty_timeout(struct usb_anchor *anchor,
716 msecs_to_jiffies(timeout)); 716 msecs_to_jiffies(timeout));
717} 717}
718EXPORT_SYMBOL_GPL(usb_wait_anchor_empty_timeout); 718EXPORT_SYMBOL_GPL(usb_wait_anchor_empty_timeout);
719
720/**
721 * usb_get_from_anchor - get an anchor's oldest urb
722 * @anchor: the anchor whose urb you want
723 *
724 * this will take the oldest urb from an anchor,
725 * unanchor and return it
726 */
727struct urb *usb_get_from_anchor(struct usb_anchor *anchor)
728{
729 struct urb *victim;
730 unsigned long flags;
731
732 spin_lock_irqsave(&anchor->lock, flags);
733 if (!list_empty(&anchor->urb_list)) {
734 victim = list_entry(anchor->urb_list.next, struct urb,
735 anchor_list);
736 usb_get_urb(victim);
737 spin_unlock_irqrestore(&anchor->lock, flags);
738 usb_unanchor_urb(victim);
739 } else {
740 spin_unlock_irqrestore(&anchor->lock, flags);
741 victim = NULL;
742 }
743
744 return victim;
745}
746
747EXPORT_SYMBOL_GPL(usb_get_from_anchor);
748
749/**
750 * usb_scuttle_anchored_urbs - unanchor all an anchor's urbs
751 * @anchor: the anchor whose urbs you want to unanchor
752 *
753 * use this to get rid of all an anchor's urbs
754 */
755void usb_scuttle_anchored_urbs(struct usb_anchor *anchor)
756{
757 struct urb *victim;
758 unsigned long flags;
759
760 spin_lock_irqsave(&anchor->lock, flags);
761 while (!list_empty(&anchor->urb_list)) {
762 victim = list_entry(anchor->urb_list.prev, struct urb,
763 anchor_list);
764 usb_get_urb(victim);
765 spin_unlock_irqrestore(&anchor->lock, flags);
766 /* this may free the URB */
767 usb_unanchor_urb(victim);
768 usb_put_urb(victim);
769 spin_lock_irqsave(&anchor->lock, flags);
770 }
771 spin_unlock_irqrestore(&anchor->lock, flags);
772}
773
774EXPORT_SYMBOL_GPL(usb_scuttle_anchored_urbs);
775
776/**
777 * usb_anchor_empty - is an anchor empty
778 * @anchor: the anchor you want to query
779 *
780 * returns 1 if the anchor has no urbs associated with it
781 */
782int usb_anchor_empty(struct usb_anchor *anchor)
783{
784 return list_empty(&anchor->urb_list);
785}
786
787EXPORT_SYMBOL_GPL(usb_anchor_empty);
788