Commit 04adba5a authored by Greg Kroah-Hartman's avatar Greg Kroah-Hartman

[PATCH] USB device reference counting api cleanup changes

This patch replaces the awkwardly named usb_inc_dev_use() and
usb_dec_dev_use() with usb_get_dev() and usb_put_dev() to match the
naming convention of the rest of the kernel's reference counted
structures.  It also does away with the special case of usb_free_dev(),
and has usb_put_dev() be the same thing (through a #define, just like
usb_free_urb() works.)

Now when the last person calls usb_put_dev() or usb_free_dev() the
structure is cleaned up.  This allows the different host controller
drivers to implement their logic differently if they want to (as they
do), and everyone can be happy and stop arguing about the "proper" way
to write their host controller drivers :)
parent 25f04c13
...@@ -1320,7 +1320,7 @@ static void urb_unlink (struct urb *urb) ...@@ -1320,7 +1320,7 @@ static void urb_unlink (struct urb *urb)
list_del_init (&urb->urb_list); list_del_init (&urb->urb_list);
dev = urb->dev; dev = urb->dev;
urb->dev = NULL; urb->dev = NULL;
usb_dec_dev_use (dev); usb_put_dev (dev);
spin_unlock_irqrestore (&hcd_data_lock, flags); spin_unlock_irqrestore (&hcd_data_lock, flags);
} }
...@@ -1516,7 +1516,7 @@ static int hcd_submit_urb (struct urb *urb, int mem_flags) ...@@ -1516,7 +1516,7 @@ static int hcd_submit_urb (struct urb *urb, int mem_flags)
spin_lock_irqsave (&hcd_data_lock, flags); spin_lock_irqsave (&hcd_data_lock, flags);
if (HCD_IS_RUNNING (hcd->state) && hcd->state != USB_STATE_QUIESCING) { if (HCD_IS_RUNNING (hcd->state) && hcd->state != USB_STATE_QUIESCING) {
usb_inc_dev_use (urb->dev); usb_get_dev (urb->dev);
list_add (&urb->urb_list, &dev->urb_list); list_add (&urb->urb_list, &dev->urb_list);
status = 0; status = 0;
} else { } else {
......
...@@ -969,21 +969,47 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent, struct usb_bus *bus) ...@@ -969,21 +969,47 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent, struct usb_bus *bus)
} }
/** /**
* usb_free_dev - free a usb device structure (usbcore-internal) * usb_get_dev - increments the reference count of the device
* @dev: the device being referenced
*
* Each live reference to a device should be refcounted.
*
* Drivers for USB interfaces should normally record such references in
* their probe() methods, when they bind to an interface, and release
* them by calling usb_put_dev(), in their disconnect() methods.
*
* A pointer to the device with the incremented reference counter is returned.
*/
struct usb_device *usb_get_dev (struct usb_device *dev)
{
if (dev) {
atomic_inc (&dev->refcnt);
return dev;
}
return NULL;
}
/**
* usb_free_dev - free a usb device structure when all users of it are finished.
* @dev: device that's been disconnected * @dev: device that's been disconnected
* Context: !in_interrupt () * Context: !in_interrupt ()
* *
* Must be called when a user of a device is finished with it. When the last
* user of the device calls this function, the memory of the device is freed.
*
* Used by hub and virtual root hub drivers. The device is completely * Used by hub and virtual root hub drivers. The device is completely
* gone, everything is cleaned up, so it's time to get rid of these last * gone, everything is cleaned up, so it's time to get rid of these last
* records of this device. * records of this device.
*/ */
void usb_free_dev(struct usb_device *dev) void usb_free_dev(struct usb_device *dev)
{ {
if (dev->bus->op->deallocate) if (atomic_dec_and_test(&dev->refcnt)) {
dev->bus->op->deallocate(dev); if (dev->bus->op->deallocate)
usb_destroy_configuration (dev); dev->bus->op->deallocate(dev);
usb_bus_put (dev->bus); usb_destroy_configuration (dev);
kfree (dev); usb_bus_put (dev->bus);
kfree (dev);
}
} }
/** /**
...@@ -1039,7 +1065,7 @@ void usb_free_urb(struct urb *urb) ...@@ -1039,7 +1065,7 @@ void usb_free_urb(struct urb *urb)
} }
/** /**
* usb_get_urb - incrementes 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
* *
* This must be called whenever a urb is transfered from a device driver to a * This must be called whenever a urb is transfered from a device driver to a
...@@ -1928,7 +1954,7 @@ void usb_disconnect(struct usb_device **pdev) ...@@ -1928,7 +1954,7 @@ void usb_disconnect(struct usb_device **pdev)
/* Decrement the reference count, it'll auto free everything when */ /* Decrement the reference count, it'll auto free everything when */
/* it hits 0 which could very well be now */ /* it hits 0 which could very well be now */
usb_dec_dev_use(dev); usb_put_dev(dev);
} }
/** /**
...@@ -2760,6 +2786,7 @@ EXPORT_SYMBOL(usb_deregister_dev); ...@@ -2760,6 +2786,7 @@ EXPORT_SYMBOL(usb_deregister_dev);
EXPORT_SYMBOL(usb_alloc_dev); EXPORT_SYMBOL(usb_alloc_dev);
EXPORT_SYMBOL(usb_free_dev); EXPORT_SYMBOL(usb_free_dev);
EXPORT_SYMBOL(usb_get_dev);
EXPORT_SYMBOL(usb_hub_tt_clear_buffer); EXPORT_SYMBOL(usb_hub_tt_clear_buffer);
EXPORT_SYMBOL(usb_find_interface_driver_for_ifnum); EXPORT_SYMBOL(usb_find_interface_driver_for_ifnum);
......
...@@ -165,7 +165,7 @@ static struct uhci_td *uhci_alloc_td(struct uhci *uhci, struct usb_device *dev) ...@@ -165,7 +165,7 @@ static struct uhci_td *uhci_alloc_td(struct uhci *uhci, struct usb_device *dev)
INIT_LIST_HEAD(&td->list); INIT_LIST_HEAD(&td->list);
INIT_LIST_HEAD(&td->fl_list); INIT_LIST_HEAD(&td->fl_list);
usb_inc_dev_use(dev); usb_get_dev(dev);
return td; return td;
} }
...@@ -317,7 +317,7 @@ static void uhci_free_td(struct uhci *uhci, struct uhci_td *td) ...@@ -317,7 +317,7 @@ static void uhci_free_td(struct uhci *uhci, struct uhci_td *td)
dbg("td is still in URB list!"); dbg("td is still in URB list!");
if (td->dev) if (td->dev)
usb_dec_dev_use(td->dev); usb_put_dev(td->dev);
pci_pool_free(uhci->td_pool, td, td->dma_handle); pci_pool_free(uhci->td_pool, td, td->dma_handle);
} }
...@@ -342,7 +342,7 @@ static struct uhci_qh *uhci_alloc_qh(struct uhci *uhci, struct usb_device *dev) ...@@ -342,7 +342,7 @@ static struct uhci_qh *uhci_alloc_qh(struct uhci *uhci, struct usb_device *dev)
INIT_LIST_HEAD(&qh->list); INIT_LIST_HEAD(&qh->list);
INIT_LIST_HEAD(&qh->remove_list); INIT_LIST_HEAD(&qh->remove_list);
usb_inc_dev_use(dev); usb_get_dev(dev);
return qh; return qh;
} }
...@@ -355,7 +355,7 @@ static void uhci_free_qh(struct uhci *uhci, struct uhci_qh *qh) ...@@ -355,7 +355,7 @@ static void uhci_free_qh(struct uhci *uhci, struct uhci_qh *qh)
dbg("qh still in remove_list!"); dbg("qh still in remove_list!");
if (qh->dev) if (qh->dev)
usb_dec_dev_use(qh->dev); usb_put_dev(qh->dev);
pci_pool_free(uhci->qh_pool, qh, qh->dma_handle); pci_pool_free(uhci->qh_pool, qh, qh->dma_handle);
} }
...@@ -1492,7 +1492,7 @@ static int uhci_submit_urb(struct urb *urb, int mem_flags) ...@@ -1492,7 +1492,7 @@ static int uhci_submit_urb(struct urb *urb, int mem_flags)
uhci = (struct uhci *)urb->dev->bus->hcpriv; uhci = (struct uhci *)urb->dev->bus->hcpriv;
INIT_LIST_HEAD(&urb->urb_list); INIT_LIST_HEAD(&urb->urb_list);
usb_inc_dev_use(urb->dev); usb_get_dev(urb->dev);
spin_lock_irqsave(&uhci->urb_list_lock, flags); spin_lock_irqsave(&uhci->urb_list_lock, flags);
spin_lock(&urb->lock); spin_lock(&urb->lock);
...@@ -1503,7 +1503,7 @@ static int uhci_submit_urb(struct urb *urb, int mem_flags) ...@@ -1503,7 +1503,7 @@ static int uhci_submit_urb(struct urb *urb, int mem_flags)
/* Since we can have problems on the out path */ /* Since we can have problems on the out path */
spin_unlock(&urb->lock); spin_unlock(&urb->lock);
spin_unlock_irqrestore(&uhci->urb_list_lock, flags); spin_unlock_irqrestore(&uhci->urb_list_lock, flags);
usb_dec_dev_use(urb->dev); usb_put_dev(urb->dev);
usb_put_urb(urb); usb_put_urb(urb);
return ret; return ret;
...@@ -2376,7 +2376,7 @@ static void uhci_call_completion(struct urb *urb) ...@@ -2376,7 +2376,7 @@ static void uhci_call_completion(struct urb *urb)
} else { } else {
/* We decrement the usage count after we're done */ /* We decrement the usage count after we're done */
/* with everything */ /* with everything */
usb_dec_dev_use(dev); usb_put_dev(dev);
usb_put_urb(urb); usb_put_urb(urb);
} }
} }
......
...@@ -210,7 +210,7 @@ static void urb_rm_priv_locked (struct urb * urb) ...@@ -210,7 +210,7 @@ static void urb_rm_priv_locked (struct urb * urb)
} }
urb_free_priv ((struct ohci *)urb->dev->bus->hcpriv, urb_priv); urb_free_priv ((struct ohci *)urb->dev->bus->hcpriv, urb_priv);
usb_dec_dev_use (urb->dev); usb_put_dev (urb->dev);
urb->dev = NULL; urb->dev = NULL;
usb_put_urb (urb); usb_put_urb (urb);
} }
...@@ -563,7 +563,7 @@ static int sohci_submit_urb (struct urb * urb, int mem_flags) ...@@ -563,7 +563,7 @@ static int sohci_submit_urb (struct urb * urb, int mem_flags)
/* increment the reference count of the urb, as we now also control it */ /* increment the reference count of the urb, as we now also control it */
urb = usb_get_urb (urb); urb = usb_get_urb (urb);
usb_inc_dev_use (urb->dev); usb_get_dev (urb->dev);
ohci = (ohci_t *) urb->dev->bus->hcpriv; ohci = (ohci_t *) urb->dev->bus->hcpriv;
#ifdef DEBUG #ifdef DEBUG
...@@ -577,14 +577,14 @@ static int sohci_submit_urb (struct urb * urb, int mem_flags) ...@@ -577,14 +577,14 @@ static int sohci_submit_urb (struct urb * urb, int mem_flags)
/* when controller's hung, permit only roothub cleanup attempts /* when controller's hung, permit only roothub cleanup attempts
* such as powering down ports */ * such as powering down ports */
if (ohci->disabled) { if (ohci->disabled) {
usb_dec_dev_use (urb->dev); usb_put_dev (urb->dev);
usb_put_urb (urb); usb_put_urb (urb);
return -ESHUTDOWN; return -ESHUTDOWN;
} }
/* every endpoint has a ed, locate and fill it */ /* every endpoint has a ed, locate and fill it */
if (!(ed = ep_add_ed (urb->dev, pipe, urb->interval, 1, mem_flags))) { if (!(ed = ep_add_ed (urb->dev, pipe, urb->interval, 1, mem_flags))) {
usb_dec_dev_use (urb->dev); usb_put_dev (urb->dev);
usb_put_urb (urb); usb_put_urb (urb);
return -ENOMEM; return -ENOMEM;
} }
...@@ -606,7 +606,7 @@ static int sohci_submit_urb (struct urb * urb, int mem_flags) ...@@ -606,7 +606,7 @@ static int sohci_submit_urb (struct urb * urb, int mem_flags)
case PIPE_ISOCHRONOUS: /* number of packets from URB */ case PIPE_ISOCHRONOUS: /* number of packets from URB */
size = urb->number_of_packets; size = urb->number_of_packets;
if (size <= 0) { if (size <= 0) {
usb_dec_dev_use (urb->dev); usb_put_dev (urb->dev);
usb_put_urb (urb); usb_put_urb (urb);
return -EINVAL; return -EINVAL;
} }
...@@ -627,7 +627,7 @@ static int sohci_submit_urb (struct urb * urb, int mem_flags) ...@@ -627,7 +627,7 @@ static int sohci_submit_urb (struct urb * urb, int mem_flags)
/* allocate the private part of the URB */ /* allocate the private part of the URB */
urb_priv = kmalloc (sizeof (urb_priv_t) + size * sizeof (td_t *), mem_flags); urb_priv = kmalloc (sizeof (urb_priv_t) + size * sizeof (td_t *), mem_flags);
if (!urb_priv) { if (!urb_priv) {
usb_dec_dev_use (urb->dev); usb_put_dev (urb->dev);
usb_put_urb (urb); usb_put_urb (urb);
return -ENOMEM; return -ENOMEM;
} }
...@@ -645,7 +645,7 @@ static int sohci_submit_urb (struct urb * urb, int mem_flags) ...@@ -645,7 +645,7 @@ static int sohci_submit_urb (struct urb * urb, int mem_flags)
urb_priv->length = i; urb_priv->length = i;
urb_free_priv (ohci, urb_priv); urb_free_priv (ohci, urb_priv);
spin_unlock_irqrestore (&usb_ed_lock, flags); spin_unlock_irqrestore (&usb_ed_lock, flags);
usb_dec_dev_use (urb->dev); usb_put_dev (urb->dev);
usb_put_urb (urb); usb_put_urb (urb);
return -ENOMEM; return -ENOMEM;
} }
...@@ -654,7 +654,7 @@ static int sohci_submit_urb (struct urb * urb, int mem_flags) ...@@ -654,7 +654,7 @@ static int sohci_submit_urb (struct urb * urb, int mem_flags)
if (ed->state == ED_NEW || (ed->state & ED_DEL)) { if (ed->state == ED_NEW || (ed->state & ED_DEL)) {
urb_free_priv (ohci, urb_priv); urb_free_priv (ohci, urb_priv);
spin_unlock_irqrestore (&usb_ed_lock, flags); spin_unlock_irqrestore (&usb_ed_lock, flags);
usb_dec_dev_use (urb->dev); usb_put_dev (urb->dev);
usb_put_urb (urb); usb_put_urb (urb);
return -EINVAL; return -EINVAL;
} }
...@@ -677,7 +677,7 @@ static int sohci_submit_urb (struct urb * urb, int mem_flags) ...@@ -677,7 +677,7 @@ static int sohci_submit_urb (struct urb * urb, int mem_flags)
if (bustime < 0) { if (bustime < 0) {
urb_free_priv (ohci, urb_priv); urb_free_priv (ohci, urb_priv);
spin_unlock_irqrestore (&usb_ed_lock, flags); spin_unlock_irqrestore (&usb_ed_lock, flags);
usb_dec_dev_use (urb->dev); usb_put_dev (urb->dev);
usb_put_urb (urb); usb_put_urb (urb);
return bustime; return bustime;
} }
...@@ -802,7 +802,7 @@ static int sohci_unlink_urb (struct urb * urb) ...@@ -802,7 +802,7 @@ static int sohci_unlink_urb (struct urb * urb)
return -ETIMEDOUT; return -ETIMEDOUT;
} }
} else { } else {
/* usb_dec_dev_use done in dl_del_list() */ /* usb_put_dev done in dl_del_list() */
urb->status = -EINPROGRESS; urb->status = -EINPROGRESS;
spin_unlock_irqrestore (&usb_ed_lock, flags); spin_unlock_irqrestore (&usb_ed_lock, flags);
return -EINPROGRESS; return -EINPROGRESS;
...@@ -2109,7 +2109,7 @@ static int rh_submit_urb (struct urb * urb) ...@@ -2109,7 +2109,7 @@ static int rh_submit_urb (struct urb * urb)
#endif #endif
urb->hcpriv = NULL; urb->hcpriv = NULL;
usb_dec_dev_use (usb_dev); usb_put_dev (usb_dev);
urb->dev = NULL; urb->dev = NULL;
if (urb->complete) if (urb->complete)
urb->complete (urb); urb->complete (urb);
...@@ -2129,7 +2129,7 @@ static int rh_unlink_urb (struct urb * urb) ...@@ -2129,7 +2129,7 @@ static int rh_unlink_urb (struct urb * urb)
ohci->rh.urb = NULL; ohci->rh.urb = NULL;
urb->hcpriv = NULL; urb->hcpriv = NULL;
usb_dec_dev_use(urb->dev); usb_put_dev (urb->dev);
urb->dev = NULL; urb->dev = NULL;
if (urb->transfer_flags & USB_ASYNC_UNLINK) { if (urb->transfer_flags & USB_ASYNC_UNLINK) {
urb->status = -ECONNRESET; urb->status = -ECONNRESET;
......
...@@ -1217,7 +1217,7 @@ _static int uhci_unlink_urb_sync (uhci_t *s, struct urb *urb) ...@@ -1217,7 +1217,7 @@ _static int uhci_unlink_urb_sync (uhci_t *s, struct urb *urb)
urb->dev = NULL; urb->dev = NULL;
urb->complete ((struct urb *) urb); urb->complete ((struct urb *) urb);
} }
usb_dec_dev_use (usb_dev); usb_put_dev (usb_dev);
usb_put_urb (urb); usb_put_urb (urb);
} }
else else
...@@ -1301,7 +1301,7 @@ _static void uhci_cleanup_unlink(uhci_t *s, int force) ...@@ -1301,7 +1301,7 @@ _static void uhci_cleanup_unlink(uhci_t *s, int force)
uhci_urb_dma_unmap(s, urb, urb_priv); uhci_urb_dma_unmap(s, urb, urb_priv);
usb_dec_dev_use (dev); usb_put_dev (dev);
#ifdef DEBUG_SLAB #ifdef DEBUG_SLAB
kmem_cache_free (urb_priv_kmem, urb_priv); kmem_cache_free (urb_priv_kmem, urb_priv);
#else #else
...@@ -1655,7 +1655,7 @@ _static int uhci_submit_urb (struct urb *urb, int mem_flags) ...@@ -1655,7 +1655,7 @@ _static int uhci_submit_urb (struct urb *urb, int mem_flags)
/* increment the reference count of the urb, as we now also control it */ /* increment the reference count of the urb, as we now also control it */
urb = usb_get_urb (urb); urb = usb_get_urb (urb);
usb_inc_dev_use (urb->dev); usb_get_dev (urb->dev);
spin_lock_irqsave (&s->urb_list_lock, flags); spin_lock_irqsave (&s->urb_list_lock, flags);
...@@ -1669,7 +1669,7 @@ _static int uhci_submit_urb (struct urb *urb, int mem_flags) ...@@ -1669,7 +1669,7 @@ _static int uhci_submit_urb (struct urb *urb, int mem_flags)
((type == PIPE_BULK) && ((type == PIPE_BULK) &&
(!(urb->transfer_flags & USB_QUEUE_BULK) || !(queued_urb->transfer_flags & USB_QUEUE_BULK)))) { (!(urb->transfer_flags & USB_QUEUE_BULK) || !(queued_urb->transfer_flags & USB_QUEUE_BULK)))) {
spin_unlock_irqrestore (&s->urb_list_lock, flags); spin_unlock_irqrestore (&s->urb_list_lock, flags);
usb_dec_dev_use (urb->dev); usb_put_dev (urb->dev);
usb_put_urb (urb); usb_put_urb (urb);
err("ENXIO %08x, flags %x, urb %p, burb %p",urb->pipe,urb->transfer_flags,urb,queued_urb); err("ENXIO %08x, flags %x, urb %p, burb %p",urb->pipe,urb->transfer_flags,urb,queued_urb);
return -ENXIO; // urb already queued return -ENXIO; // urb already queued
...@@ -1682,7 +1682,7 @@ _static int uhci_submit_urb (struct urb *urb, int mem_flags) ...@@ -1682,7 +1682,7 @@ _static int uhci_submit_urb (struct urb *urb, int mem_flags)
urb_priv = kmalloc (sizeof (urb_priv_t), mem_flags); urb_priv = kmalloc (sizeof (urb_priv_t), mem_flags);
#endif #endif
if (!urb_priv) { if (!urb_priv) {
usb_dec_dev_use (urb->dev); usb_put_dev (urb->dev);
spin_unlock_irqrestore (&s->urb_list_lock, flags); spin_unlock_irqrestore (&s->urb_list_lock, flags);
usb_put_urb (urb); usb_put_urb (urb);
return -ENOMEM; return -ENOMEM;
...@@ -1767,7 +1767,7 @@ _static int uhci_submit_urb (struct urb *urb, int mem_flags) ...@@ -1767,7 +1767,7 @@ _static int uhci_submit_urb (struct urb *urb, int mem_flags)
if (ret != 0) { if (ret != 0) {
uhci_urb_dma_unmap(s, urb, urb_priv); uhci_urb_dma_unmap(s, urb, urb_priv);
usb_dec_dev_use (urb->dev); usb_put_dev (urb->dev);
#ifdef DEBUG_SLAB #ifdef DEBUG_SLAB
kmem_cache_free(urb_priv_kmem, urb_priv); kmem_cache_free(urb_priv_kmem, urb_priv);
#else #else
...@@ -2737,7 +2737,7 @@ _static int process_urb (uhci_t *s, struct list_head *p) ...@@ -2737,7 +2737,7 @@ _static int process_urb (uhci_t *s, struct list_head *p)
spin_lock(&s->urb_list_lock); spin_lock(&s->urb_list_lock);
} }
usb_dec_dev_use (usb_dev); usb_put_dev (usb_dev);
usb_put_urb (urb); usb_put_urb (urb);
} }
} }
......
...@@ -970,7 +970,7 @@ static void usbvideo_Disconnect(struct usb_device *dev, void *ptr) ...@@ -970,7 +970,7 @@ static void usbvideo_Disconnect(struct usb_device *dev, void *ptr)
for (i=0; i < USBVIDEO_NUMSBUF; i++) for (i=0; i < USBVIDEO_NUMSBUF; i++)
usb_free_urb(uvd->sbuf[i].urb); usb_free_urb(uvd->sbuf[i].urb);
usb_dec_dev_use(uvd->dev); usb_put_dev(uvd->dev);
uvd->dev = NULL; /* USB device is no more */ uvd->dev = NULL; /* USB device is no more */
video_unregister_device(&uvd->vdev); video_unregister_device(&uvd->vdev);
...@@ -1176,7 +1176,7 @@ int usbvideo_RegisterVideoDevice(uvd_t *uvd) ...@@ -1176,7 +1176,7 @@ int usbvideo_RegisterVideoDevice(uvd_t *uvd)
} }
#endif #endif
usb_inc_dev_use(uvd->dev); usb_get_dev(uvd->dev);
return 0; return 0;
} }
......
...@@ -1256,7 +1256,7 @@ static void * CDCEther_probe( struct usb_device *usb, unsigned int ifnum, ...@@ -1256,7 +1256,7 @@ static void * CDCEther_probe( struct usb_device *usb, unsigned int ifnum,
ether_dev ); ether_dev );
// Does this REALLY do anything??? // Does this REALLY do anything???
usb_inc_dev_use( usb ); usb_get_dev( usb );
// TODO - last minute HACK // TODO - last minute HACK
ether_dev->comm_ep_in = 5; ether_dev->comm_ep_in = 5;
...@@ -1298,7 +1298,7 @@ static void CDCEther_disconnect( struct usb_device *usb, void *ptr ) ...@@ -1298,7 +1298,7 @@ static void CDCEther_disconnect( struct usb_device *usb, void *ptr )
ether_dev->net = NULL; ether_dev->net = NULL;
// I ask again, does this do anything??? // I ask again, does this do anything???
usb_dec_dev_use( usb ); usb_put_dev( usb );
// We are done with this interface // We are done with this interface
usb_driver_release_interface( &CDCEther_driver, usb_driver_release_interface( &CDCEther_driver,
......
...@@ -981,7 +981,7 @@ static void *pegasus_probe(struct usb_device *dev, unsigned int ifnum, ...@@ -981,7 +981,7 @@ static void *pegasus_probe(struct usb_device *dev, unsigned int ifnum,
return NULL; return NULL;
} }
usb_inc_dev_use(dev); usb_get_dev(dev);
memset(pegasus, 0, sizeof(struct pegasus)); memset(pegasus, 0, sizeof(struct pegasus));
pegasus->dev_index = dev_index; pegasus->dev_index = dev_index;
init_waitqueue_head(&pegasus->ctrl_wait); init_waitqueue_head(&pegasus->ctrl_wait);
...@@ -1086,7 +1086,7 @@ static void pegasus_disconnect(struct usb_device *dev, void *ptr) ...@@ -1086,7 +1086,7 @@ static void pegasus_disconnect(struct usb_device *dev, void *ptr)
pegasus->flags |= PEGASUS_UNPLUG; pegasus->flags |= PEGASUS_UNPLUG;
unregister_netdev(pegasus->net); unregister_netdev(pegasus->net);
usb_dec_dev_use(dev); usb_put_dev(dev);
usb_unlink_urb(pegasus->intr_urb); usb_unlink_urb(pegasus->intr_urb);
usb_unlink_urb(pegasus->tx_urb); usb_unlink_urb(pegasus->tx_urb);
usb_unlink_urb(pegasus->rx_urb); usb_unlink_urb(pegasus->rx_urb);
......
...@@ -1951,7 +1951,7 @@ static void usbnet_disconnect (struct usb_device *udev, void *ptr) ...@@ -1951,7 +1951,7 @@ static void usbnet_disconnect (struct usb_device *udev, void *ptr)
flush_scheduled_tasks (); flush_scheduled_tasks ();
kfree (dev); kfree (dev);
usb_dec_dev_use (udev); usb_put_dev (udev);
} }
...@@ -1997,7 +1997,7 @@ usbnet_probe (struct usb_device *udev, unsigned ifnum, ...@@ -1997,7 +1997,7 @@ usbnet_probe (struct usb_device *udev, unsigned ifnum,
memset (dev, 0, sizeof *dev); memset (dev, 0, sizeof *dev);
init_MUTEX_LOCKED (&dev->mutex); init_MUTEX_LOCKED (&dev->mutex);
usb_inc_dev_use (udev); usb_get_dev (udev);
dev->udev = udev; dev->udev = udev;
dev->driver_info = info; dev->driver_info = info;
dev->msg_level = msg_level; dev->msg_level = msg_level;
......
...@@ -676,7 +676,7 @@ static void * storage_probe(struct usb_device *dev, unsigned int ifnum, ...@@ -676,7 +676,7 @@ static void * storage_probe(struct usb_device *dev, unsigned int ifnum,
} }
/* At this point, we're committed to using the device */ /* At this point, we're committed to using the device */
usb_inc_dev_use(dev); usb_get_dev(dev);
/* clear the GUID and fetch the strings */ /* clear the GUID and fetch the strings */
GUID_CLEAR(guid); GUID_CLEAR(guid);
...@@ -735,14 +735,14 @@ static void * storage_probe(struct usb_device *dev, unsigned int ifnum, ...@@ -735,14 +735,14 @@ static void * storage_probe(struct usb_device *dev, unsigned int ifnum,
/* allocate an IRQ callback if one is needed */ /* allocate an IRQ callback if one is needed */
if ((ss->protocol == US_PR_CBI) && usb_stor_allocate_irq(ss)) { if ((ss->protocol == US_PR_CBI) && usb_stor_allocate_irq(ss)) {
usb_dec_dev_use(dev); usb_put_dev(dev);
return NULL; return NULL;
} }
/* allocate the URB we're going to use */ /* allocate the URB we're going to use */
ss->current_urb = usb_alloc_urb(0, GFP_KERNEL); ss->current_urb = usb_alloc_urb(0, GFP_KERNEL);
if (!ss->current_urb) { if (!ss->current_urb) {
usb_dec_dev_use(dev); usb_put_dev(dev);
return NULL; return NULL;
} }
...@@ -760,7 +760,7 @@ static void * storage_probe(struct usb_device *dev, unsigned int ifnum, ...@@ -760,7 +760,7 @@ static void * storage_probe(struct usb_device *dev, unsigned int ifnum,
if ((ss = (struct us_data *)kmalloc(sizeof(struct us_data), if ((ss = (struct us_data *)kmalloc(sizeof(struct us_data),
GFP_KERNEL)) == NULL) { GFP_KERNEL)) == NULL) {
printk(KERN_WARNING USB_STORAGE "Out of memory\n"); printk(KERN_WARNING USB_STORAGE "Out of memory\n");
usb_dec_dev_use(dev); usb_put_dev(dev);
return NULL; return NULL;
} }
memset(ss, 0, sizeof(struct us_data)); memset(ss, 0, sizeof(struct us_data));
...@@ -769,7 +769,7 @@ static void * storage_probe(struct usb_device *dev, unsigned int ifnum, ...@@ -769,7 +769,7 @@ static void * storage_probe(struct usb_device *dev, unsigned int ifnum,
ss->current_urb = usb_alloc_urb(0, GFP_KERNEL); ss->current_urb = usb_alloc_urb(0, GFP_KERNEL);
if (!ss->current_urb) { if (!ss->current_urb) {
kfree(ss); kfree(ss);
usb_dec_dev_use(dev); usb_put_dev(dev);
return NULL; return NULL;
} }
...@@ -919,7 +919,7 @@ static void * storage_probe(struct usb_device *dev, unsigned int ifnum, ...@@ -919,7 +919,7 @@ static void * storage_probe(struct usb_device *dev, unsigned int ifnum,
ss->transport_name = "Unknown"; ss->transport_name = "Unknown";
kfree(ss->current_urb); kfree(ss->current_urb);
kfree(ss); kfree(ss);
usb_dec_dev_use(dev); usb_put_dev(dev);
return NULL; return NULL;
break; break;
} }
...@@ -974,7 +974,7 @@ static void * storage_probe(struct usb_device *dev, unsigned int ifnum, ...@@ -974,7 +974,7 @@ static void * storage_probe(struct usb_device *dev, unsigned int ifnum,
ss->protocol_name = "Unknown"; ss->protocol_name = "Unknown";
kfree(ss->current_urb); kfree(ss->current_urb);
kfree(ss); kfree(ss);
usb_dec_dev_use(dev); usb_put_dev(dev);
return NULL; return NULL;
break; break;
} }
...@@ -984,7 +984,7 @@ static void * storage_probe(struct usb_device *dev, unsigned int ifnum, ...@@ -984,7 +984,7 @@ static void * storage_probe(struct usb_device *dev, unsigned int ifnum,
if ((ss->protocol == US_PR_CBI) && usb_stor_allocate_irq(ss)) { if ((ss->protocol == US_PR_CBI) && usb_stor_allocate_irq(ss)) {
kfree(ss->current_urb); kfree(ss->current_urb);
kfree(ss); kfree(ss);
usb_dec_dev_use(dev); usb_put_dev(dev);
return NULL; return NULL;
} }
...@@ -1020,7 +1020,7 @@ static void * storage_probe(struct usb_device *dev, unsigned int ifnum, ...@@ -1020,7 +1020,7 @@ static void * storage_probe(struct usb_device *dev, unsigned int ifnum,
"Unable to start control thread\n"); "Unable to start control thread\n");
kfree(ss->current_urb); kfree(ss->current_urb);
kfree(ss); kfree(ss);
usb_dec_dev_use(dev); usb_put_dev(dev);
return NULL; return NULL;
} }
...@@ -1087,7 +1087,7 @@ static void storage_disconnect(struct usb_device *dev, void *ptr) ...@@ -1087,7 +1087,7 @@ static void storage_disconnect(struct usb_device *dev, void *ptr)
ss->current_urb = NULL; ss->current_urb = NULL;
/* mark the device as gone */ /* mark the device as gone */
usb_dec_dev_use(ss->pusb_dev); usb_put_dev(ss->pusb_dev);
ss->pusb_dev = NULL; ss->pusb_dev = NULL;
atomic_set(&ss->sm_state, US_STATE_DETACHED); atomic_set(&ss->sm_state, US_STATE_DETACHED);
......
...@@ -426,10 +426,10 @@ struct usb_device { ...@@ -426,10 +426,10 @@ struct usb_device {
struct usb_device *children[USB_MAXCHILDREN]; struct usb_device *children[USB_MAXCHILDREN];
}; };
/* usb_free_dev can be called anywhere from usb_dec_dev_use */ extern struct usb_device *usb_alloc_dev(struct usb_device *parent, struct usb_bus *);
extern struct usb_device *usb_alloc_dev(struct usb_device *parent, extern struct usb_device *usb_get_dev(struct usb_device *dev);
struct usb_bus *);
extern void usb_free_dev(struct usb_device *); extern void usb_free_dev(struct usb_device *);
#define usb_put_dev usb_free_dev
/* for when layers above USB add new non-USB drivers */ /* for when layers above USB add new non-USB drivers */
extern void usb_scan_devices(void); extern void usb_scan_devices(void);
...@@ -440,34 +440,6 @@ extern int usb_reset_device(struct usb_device *dev); ...@@ -440,34 +440,6 @@ extern int usb_reset_device(struct usb_device *dev);
/* for drivers using iso endpoints */ /* for drivers using iso endpoints */
extern int usb_get_current_frame_number (struct usb_device *usb_dev); extern int usb_get_current_frame_number (struct usb_device *usb_dev);
/**
* usb_inc_dev_use - record another reference to a device
* @dev: the device being referenced
*
* Each live reference to a device should be refcounted.
*
* Drivers for USB interfaces should normally record such references in
* their probe() methods, when they bind to an interface, and release
* them usb_dec_dev_use(), in their disconnect() methods.
*/
static inline void usb_inc_dev_use (struct usb_device *dev)
{
atomic_inc (&dev->refcnt);
}
/**
* usb_dec_dev_use - drop a reference to a device
* @dev: the device no longer being referenced
*
* Each live reference to a device should be refcounted.
*/
static inline void usb_dec_dev_use (struct usb_device *dev)
{
if (atomic_dec_and_test(&dev->refcnt))
usb_free_dev(dev);
}
/* used these for multi-interface device registration */ /* used these for multi-interface device registration */
extern int usb_find_interface_driver_for_ifnum(struct usb_device *dev, unsigned int ifnum); extern int usb_find_interface_driver_for_ifnum(struct usb_device *dev, unsigned int ifnum);
extern void usb_driver_claim_interface(struct usb_driver *driver, extern void usb_driver_claim_interface(struct usb_driver *driver,
......
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