ChangeSet 1.1371.759.33, 2004/04/26 17:07:28-07:00, greg@kroah.com USB: switch struct urb to use a kref instead of it's own atomic_t drivers/usb/core/urb.c | 21 +++++++++++++-------- include/linux/usb.h | 3 ++- 2 files changed, 15 insertions(+), 9 deletions(-) diff -Nru a/drivers/usb/core/urb.c b/drivers/usb/core/urb.c --- a/drivers/usb/core/urb.c Fri May 14 15:32:12 2004 +++ b/drivers/usb/core/urb.c Fri May 14 15:32:12 2004 @@ -13,6 +13,14 @@ #include #include "hcd.h" +#define to_urb(d) container_of(d, struct urb, kref) + +static void urb_destroy(struct kref *kref) +{ + struct urb *urb = to_urb(kref); + kfree(urb); +} + /** * usb_init_urb - initializes a urb so that it can be used by a USB driver * @urb: pointer to the urb to initialize @@ -31,7 +39,7 @@ { if (urb) { memset(urb, 0, sizeof(*urb)); - urb->count = (atomic_t)ATOMIC_INIT(1); + kref_init(&urb->kref, urb_destroy); spin_lock_init(&urb->lock); } } @@ -80,8 +88,7 @@ void usb_free_urb(struct urb *urb) { if (urb) - if (atomic_dec_and_test(&urb->count)) - kfree(urb); + kref_put(&urb->kref); } /** @@ -96,11 +103,9 @@ */ struct urb * usb_get_urb(struct urb *urb) { - if (urb) { - atomic_inc(&urb->count); - return urb; - } else - return NULL; + if (urb) + kref_get(&urb->kref); + return urb; } diff -Nru a/include/linux/usb.h b/include/linux/usb.h --- a/include/linux/usb.h Fri May 14 15:32:12 2004 +++ b/include/linux/usb.h Fri May 14 15:32:12 2004 @@ -14,6 +14,7 @@ #include /* for mdelay() */ #include /* for in_interrupt() */ #include /* for struct list_head */ +#include /* for struct kref */ #include /* for struct device */ #include /* for struct file_operations */ #include /* for struct completion */ @@ -731,8 +732,8 @@ struct urb { /* private, usb core and host controller only fields in the urb */ + struct kref kref; /* reference count of the URB */ spinlock_t lock; /* lock for the URB */ - atomic_t count; /* reference count of the URB */ void *hcpriv; /* private data for host controller */ struct list_head urb_list; /* list pointer to all active urbs */ int bandwidth; /* bandwidth for INT/ISO request */