diff options
| author | Greg Kroah-Hartman <greg@kroah.com> | 2003-04-29 01:12:04 -0700 |
|---|---|---|
| committer | Greg Kroah-Hartman <greg@kroah.com> | 2003-04-29 01:12:04 -0700 |
| commit | efead44aa238985b778ae392dc44bae634632bc6 (patch) | |
| tree | 1e7519dfc516aaf6ff7ab8a40a68ce64e26722f0 | |
| parent | 30a9f6e334289589ffcbdcaa11a75b1fc35e84db (diff) | |
USB: create usb_init_urb() for those people who like to live dangerously (like the bluetooth stack.)
| -rw-r--r-- | drivers/usb/core/urb.c | 31 | ||||
| -rw-r--r-- | include/linux/usb.h | 1 |
2 files changed, 26 insertions, 6 deletions
diff --git a/drivers/usb/core/urb.c b/drivers/usb/core/urb.c index 42e237c8e8ee..b130401bdc80 100644 --- a/drivers/usb/core/urb.c +++ b/drivers/usb/core/urb.c @@ -14,6 +14,29 @@ #include "hcd.h" /** + * usb_init_urb - initializes a urb so that it can be used by a USB driver + * @urb: pointer to the urb to initialize + * + * Initializes a urb so that the USB subsystem can use it properly. + * + * If a urb is created with a call to usb_alloc_urb() it is not + * necessary to call this function. Only use this if you allocate the + * space for a struct urb on your own. If you call this function, be + * careful when freeing the memory for your urb that it is no longer in + * use by the USB core. + * + * Only use this function if you _really_ understand what you are doing. + */ +void usb_init_urb(struct urb *urb) +{ + if (urb) { + memset(urb, 0, sizeof(*urb)); + urb->count = (atomic_t)ATOMIC_INIT(1); + spin_lock_init(&urb->lock); + } +} + +/** * usb_alloc_urb - creates a new urb for a USB driver to use * @iso_packets: number of iso packets for this urb * @mem_flags: the type of memory to allocate, see kmalloc() for a list of @@ -40,11 +63,7 @@ struct urb *usb_alloc_urb(int iso_packets, int mem_flags) err("alloc_urb: kmalloc failed"); return NULL; } - - memset(urb, 0, sizeof(*urb)); - urb->count = (atomic_t)ATOMIC_INIT(1); - spin_lock_init(&urb->lock); - + usb_init_urb(urb); return urb; } @@ -387,7 +406,7 @@ int usb_unlink_urb(struct urb *urb) return -ENODEV; } -// asynchronous request completion model +EXPORT_SYMBOL(usb_init_urb); EXPORT_SYMBOL(usb_alloc_urb); EXPORT_SYMBOL(usb_free_urb); EXPORT_SYMBOL(usb_get_urb); diff --git a/include/linux/usb.h b/include/linux/usb.h index cd50f3ede6d3..e61d0f12eddc 100644 --- a/include/linux/usb.h +++ b/include/linux/usb.h @@ -765,6 +765,7 @@ static inline void usb_fill_int_urb (struct urb *urb, urb->start_frame = -1; } +extern void usb_init_urb(struct urb *urb); extern struct urb *usb_alloc_urb(int iso_packets, int mem_flags); extern void usb_free_urb(struct urb *urb); #define usb_put_urb usb_free_urb |
