Commit 67cca2e6 authored by Alan Stern's avatar Alan Stern Committed by Greg Kroah-Hartman

[PATCH] USB: Allow NULL argument in usb_unlink_urb() and usb_kill_urb()

It makes sense for APIs involved in cleanup activities (like kfree()) to
accept NULL arguments.  Doing so frees drivers from the responsibility of
checking whether each resource was actually acquired before trying to
release it.  Accordingly, this patch makes usb_unlink_urb() and
usb_kill_urb() accept a NULL pointer (which used to be acceptable until I
changed it) and notes explicitly in the kerneldoc that such arguments are
permitted.
Signed-off-by: default avatarAlan Stern <stern@rowland.harvard.edu>
Signed-off-by: default avatarGreg Kroah-Hartman <greg@kroah.com>
parent b6157a96
...@@ -77,7 +77,7 @@ struct urb *usb_alloc_urb(int iso_packets, int mem_flags) ...@@ -77,7 +77,7 @@ struct urb *usb_alloc_urb(int iso_packets, int mem_flags)
/** /**
* usb_free_urb - frees the memory used by a urb when all users of it are finished * usb_free_urb - frees the memory used by a urb when all users of it are finished
* @urb: pointer to the urb to free * @urb: pointer to the urb to free, may be NULL
* *
* Must be called when a user of a urb is finished with it. When the last user * Must be called when a user of a urb is finished with it. When the last user
* of the urb calls this function, the memory of the urb is freed. * of the urb calls this function, the memory of the urb is freed.
...@@ -93,7 +93,7 @@ void usb_free_urb(struct urb *urb) ...@@ -93,7 +93,7 @@ void usb_free_urb(struct urb *urb)
/** /**
* usb_get_urb - increments the reference count of the urb * usb_get_urb - increments the reference count of the urb
* @urb: pointer to the urb to modify * @urb: pointer to the urb to modify, may be NULL
* *
* This must be called whenever a urb is transferred from a device driver to a * This must be called whenever a urb is transferred from a device driver to a
* host controller driver. This allows proper reference counting to happen * host controller driver. This allows proper reference counting to happen
...@@ -398,7 +398,8 @@ int usb_submit_urb(struct urb *urb, int mem_flags) ...@@ -398,7 +398,8 @@ int usb_submit_urb(struct urb *urb, int mem_flags)
/** /**
* usb_unlink_urb - abort/cancel a transfer request for an endpoint * usb_unlink_urb - abort/cancel a transfer request for an endpoint
* @urb: pointer to urb describing a previously submitted request * @urb: pointer to urb describing a previously submitted request,
* may be NULL
* *
* This routine cancels an in-progress request. URBs complete only * This routine cancels an in-progress request. URBs complete only
* once per submission, and may be canceled only once per submission. * once per submission, and may be canceled only once per submission.
...@@ -454,6 +455,8 @@ int usb_submit_urb(struct urb *urb, int mem_flags) ...@@ -454,6 +455,8 @@ int usb_submit_urb(struct urb *urb, int mem_flags)
*/ */
int usb_unlink_urb(struct urb *urb) int usb_unlink_urb(struct urb *urb)
{ {
if (!urb)
return -EINVAL;
if (!(urb->transfer_flags & URB_ASYNC_UNLINK)) { if (!(urb->transfer_flags & URB_ASYNC_UNLINK)) {
usb_kill_urb(urb); usb_kill_urb(urb);
return 0; return 0;
...@@ -465,7 +468,8 @@ int usb_unlink_urb(struct urb *urb) ...@@ -465,7 +468,8 @@ int usb_unlink_urb(struct urb *urb)
/** /**
* usb_kill_urb - cancel a transfer request and wait for it to finish * usb_kill_urb - cancel a transfer request and wait for it to finish
* @urb: pointer to URB describing a previously submitted request * @urb: pointer to URB describing a previously submitted request,
* may be NULL
* *
* This routine cancels an in-progress request. It is guaranteed that * This routine cancels an in-progress request. It is guaranteed that
* upon return all completion handlers will have finished and the URB * upon return all completion handlers will have finished and the URB
...@@ -484,7 +488,7 @@ int usb_unlink_urb(struct urb *urb) ...@@ -484,7 +488,7 @@ int usb_unlink_urb(struct urb *urb)
*/ */
void usb_kill_urb(struct urb *urb) void usb_kill_urb(struct urb *urb)
{ {
if (!(urb->dev && urb->dev->bus && urb->dev->bus->op)) if (!(urb && urb->dev && urb->dev->bus && urb->dev->bus->op))
return; return;
spin_lock_irq(&urb->lock); spin_lock_irq(&urb->lock);
++urb->reject; ++urb->reject;
......
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