Commit 49367d8f authored by Ming Lei's avatar Ming Lei Committed by Greg Kroah-Hartman

USB: mark "reject" field of struct urb as atomic_t

It is enough to protect accesses to reject field of urb
by marking it as atomic_t,also it is the only reason of
existence of usb_reject_lock,so remove the lock to make
code more clean.
Signed-off-by: default avatarMing Lei <tom.leiming@gmail.com>
Acked-off-by: default avatarAlan Stern <stern@rowland.harvard.edu>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 3b23dd6f
...@@ -1010,7 +1010,7 @@ int usb_hcd_link_urb_to_ep(struct usb_hcd *hcd, struct urb *urb) ...@@ -1010,7 +1010,7 @@ int usb_hcd_link_urb_to_ep(struct usb_hcd *hcd, struct urb *urb)
spin_lock(&hcd_urb_list_lock); spin_lock(&hcd_urb_list_lock);
/* Check that the URB isn't being killed */ /* Check that the URB isn't being killed */
if (unlikely(urb->reject)) { if (unlikely(atomic_read(&urb->reject))) {
rc = -EPERM; rc = -EPERM;
goto done; goto done;
} }
...@@ -1340,7 +1340,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags) ...@@ -1340,7 +1340,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
INIT_LIST_HEAD(&urb->urb_list); INIT_LIST_HEAD(&urb->urb_list);
atomic_dec(&urb->use_count); atomic_dec(&urb->use_count);
atomic_dec(&urb->dev->urbnum); atomic_dec(&urb->dev->urbnum);
if (urb->reject) if (atomic_read(&urb->reject))
wake_up(&usb_kill_urb_queue); wake_up(&usb_kill_urb_queue);
usb_put_urb(urb); usb_put_urb(urb);
} }
...@@ -1444,7 +1444,7 @@ void usb_hcd_giveback_urb(struct usb_hcd *hcd, struct urb *urb, int status) ...@@ -1444,7 +1444,7 @@ void usb_hcd_giveback_urb(struct usb_hcd *hcd, struct urb *urb, int status)
urb->status = status; urb->status = status;
urb->complete (urb); urb->complete (urb);
atomic_dec (&urb->use_count); atomic_dec (&urb->use_count);
if (unlikely (urb->reject)) if (unlikely(atomic_read(&urb->reject)))
wake_up (&usb_kill_urb_queue); wake_up (&usb_kill_urb_queue);
usb_put_urb (urb); usb_put_urb (urb);
} }
......
...@@ -10,7 +10,6 @@ ...@@ -10,7 +10,6 @@
#define to_urb(d) container_of(d, struct urb, kref) #define to_urb(d) container_of(d, struct urb, kref)
static DEFINE_SPINLOCK(usb_reject_lock);
static void urb_destroy(struct kref *kref) static void urb_destroy(struct kref *kref)
{ {
...@@ -131,9 +130,7 @@ void usb_anchor_urb(struct urb *urb, struct usb_anchor *anchor) ...@@ -131,9 +130,7 @@ void usb_anchor_urb(struct urb *urb, struct usb_anchor *anchor)
urb->anchor = anchor; urb->anchor = anchor;
if (unlikely(anchor->poisoned)) { if (unlikely(anchor->poisoned)) {
spin_lock(&usb_reject_lock); atomic_inc(&urb->reject);
urb->reject++;
spin_unlock(&usb_reject_lock);
} }
spin_unlock_irqrestore(&anchor->lock, flags); spin_unlock_irqrestore(&anchor->lock, flags);
...@@ -565,16 +562,12 @@ void usb_kill_urb(struct urb *urb) ...@@ -565,16 +562,12 @@ void usb_kill_urb(struct urb *urb)
might_sleep(); might_sleep();
if (!(urb && urb->dev && urb->ep)) if (!(urb && urb->dev && urb->ep))
return; return;
spin_lock_irq(&usb_reject_lock); atomic_inc(&urb->reject);
++urb->reject;
spin_unlock_irq(&usb_reject_lock);
usb_hcd_unlink_urb(urb, -ENOENT); usb_hcd_unlink_urb(urb, -ENOENT);
wait_event(usb_kill_urb_queue, atomic_read(&urb->use_count) == 0); wait_event(usb_kill_urb_queue, atomic_read(&urb->use_count) == 0);
spin_lock_irq(&usb_reject_lock); atomic_dec(&urb->reject);
--urb->reject;
spin_unlock_irq(&usb_reject_lock);
} }
EXPORT_SYMBOL_GPL(usb_kill_urb); EXPORT_SYMBOL_GPL(usb_kill_urb);
...@@ -606,9 +599,7 @@ void usb_poison_urb(struct urb *urb) ...@@ -606,9 +599,7 @@ void usb_poison_urb(struct urb *urb)
might_sleep(); might_sleep();
if (!(urb && urb->dev && urb->ep)) if (!(urb && urb->dev && urb->ep))
return; return;
spin_lock_irq(&usb_reject_lock); atomic_inc(&urb->reject);
++urb->reject;
spin_unlock_irq(&usb_reject_lock);
usb_hcd_unlink_urb(urb, -ENOENT); usb_hcd_unlink_urb(urb, -ENOENT);
wait_event(usb_kill_urb_queue, atomic_read(&urb->use_count) == 0); wait_event(usb_kill_urb_queue, atomic_read(&urb->use_count) == 0);
...@@ -617,14 +608,10 @@ EXPORT_SYMBOL_GPL(usb_poison_urb); ...@@ -617,14 +608,10 @@ EXPORT_SYMBOL_GPL(usb_poison_urb);
void usb_unpoison_urb(struct urb *urb) void usb_unpoison_urb(struct urb *urb)
{ {
unsigned long flags;
if (!urb) if (!urb)
return; return;
spin_lock_irqsave(&usb_reject_lock, flags); atomic_dec(&urb->reject);
--urb->reject;
spin_unlock_irqrestore(&usb_reject_lock, flags);
} }
EXPORT_SYMBOL_GPL(usb_unpoison_urb); EXPORT_SYMBOL_GPL(usb_unpoison_urb);
......
...@@ -1340,7 +1340,7 @@ struct urb { ...@@ -1340,7 +1340,7 @@ struct urb {
struct kref kref; /* reference count of the URB */ struct kref kref; /* reference count of the URB */
void *hcpriv; /* private data for host controller */ void *hcpriv; /* private data for host controller */
atomic_t use_count; /* concurrent submissions counter */ atomic_t use_count; /* concurrent submissions counter */
u8 reject; /* submissions will fail */ atomic_t reject; /* submissions will fail */
int unlinked; /* unlink error code */ int unlinked; /* unlink error code */
/* public: documented fields in the urb that can be used by drivers */ /* public: documented fields in the urb that can be used by drivers */
......
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