vserver 1.9.3
[linux-2.6.git] / drivers / usb / host / ehci-mem.c
index e04da1f..beee4d9 100644 (file)
@@ -47,7 +47,7 @@ static struct usb_hcd *ehci_hcd_alloc (void)
                ehci->hcd.product_desc = "EHCI Host Controller";
                return &ehci->hcd;
        }
-       return 0;
+       return NULL;
 }
 
 static void ehci_hcd_free (struct usb_hcd *hcd)
@@ -87,6 +87,22 @@ static inline void ehci_qtd_free (struct ehci_hcd *ehci, struct ehci_qtd *qtd)
 }
 
 
+static void qh_destroy (struct kref *kref)
+{
+       struct ehci_qh *qh = container_of(kref, struct ehci_qh, kref);
+       struct ehci_hcd *ehci = qh->ehci;
+
+       /* clean qtds first, and know this is not linked */
+       if (!list_empty (&qh->qtd_list) || qh->qh_next.ptr) {
+               ehci_dbg (ehci, "unused qh not empty!\n");
+               BUG ();
+       }
+       if (qh->dummy)
+               ehci_qtd_free (ehci, qh->dummy);
+       usb_put_dev (qh->dev);
+       dma_pool_free (ehci->qh_pool, qh, qh->qh_dma);
+}
+
 static struct ehci_qh *ehci_qh_alloc (struct ehci_hcd *ehci, int flags)
 {
        struct ehci_qh          *qh;
@@ -98,7 +114,8 @@ static struct ehci_qh *ehci_qh_alloc (struct ehci_hcd *ehci, int flags)
                return qh;
 
        memset (qh, 0, sizeof *qh);
-       atomic_set (&qh->refcount, 1);
+       kref_init(&qh->kref);
+       qh->ehci = ehci;
        qh->qh_dma = dma;
        // INIT_LIST_HEAD (&qh->qh_list);
        INIT_LIST_HEAD (&qh->qtd_list);
@@ -108,31 +125,21 @@ static struct ehci_qh *ehci_qh_alloc (struct ehci_hcd *ehci, int flags)
        if (qh->dummy == 0) {
                ehci_dbg (ehci, "no dummy td\n");
                dma_pool_free (ehci->qh_pool, qh, qh->qh_dma);
-               qh = 0;
+               qh = NULL;
        }
        return qh;
 }
 
 /* to share a qh (cpu threads, or hc) */
-static inline struct ehci_qh *qh_get (/* ehci, */ struct ehci_qh *qh)
+static inline struct ehci_qh *qh_get (struct ehci_qh *qh)
 {
-       atomic_inc (&qh->refcount);
+       kref_get(&qh->kref);
        return qh;
 }
 
-static void qh_put (struct ehci_hcd *ehci, struct ehci_qh *qh)
+static inline void qh_put (struct ehci_qh *qh)
 {
-       if (!atomic_dec_and_test (&qh->refcount))
-               return;
-       /* clean qtds first, and know this is not linked */
-       if (!list_empty (&qh->qtd_list) || qh->qh_next.ptr) {
-               ehci_dbg (ehci, "unused qh not empty!\n");
-               BUG ();
-       }
-       if (qh->dummy)
-               ehci_qtd_free (ehci, qh->dummy);
-       usb_put_dev (qh->dev);
-       dma_pool_free (ehci->qh_pool, qh, qh->qh_dma);
+       kref_put(&qh->kref, qh_destroy);
 }
 
 /*-------------------------------------------------------------------------*/
@@ -145,37 +152,37 @@ static void qh_put (struct ehci_hcd *ehci, struct ehci_qh *qh)
 static void ehci_mem_cleanup (struct ehci_hcd *ehci)
 {
        if (ehci->async)
-               qh_put (ehci, ehci->async);
-       ehci->async = 0;
+               qh_put (ehci->async);
+       ehci->async = NULL;
 
        /* DMA consistent memory and pools */
        if (ehci->qtd_pool)
                dma_pool_destroy (ehci->qtd_pool);
-       ehci->qtd_pool = 0;
+       ehci->qtd_pool = NULL;
 
        if (ehci->qh_pool) {
                dma_pool_destroy (ehci->qh_pool);
-               ehci->qh_pool = 0;
+               ehci->qh_pool = NULL;
        }
 
        if (ehci->itd_pool)
                dma_pool_destroy (ehci->itd_pool);
-       ehci->itd_pool = 0;
+       ehci->itd_pool = NULL;
 
        if (ehci->sitd_pool)
                dma_pool_destroy (ehci->sitd_pool);
-       ehci->sitd_pool = 0;
+       ehci->sitd_pool = NULL;
 
        if (ehci->periodic)
                dma_free_coherent (ehci->hcd.self.controller,
                        ehci->periodic_size * sizeof (u32),
                        ehci->periodic, ehci->periodic_dma);
-       ehci->periodic = 0;
+       ehci->periodic = NULL;
 
        /* shadow periodic table */
        if (ehci->pshadow)
                kfree (ehci->pshadow);
-       ehci->pshadow = 0;
+       ehci->pshadow = NULL;
 }
 
 /* remember to add cleanup code (above) if you add anything here */
@@ -228,9 +235,9 @@ static int ehci_mem_init (struct ehci_hcd *ehci, int flags)
        }
 
        /* Hardware periodic table */
-       ehci->periodic = (u32 *)
+       ehci->periodic = (__le32 *)
                dma_alloc_coherent (ehci->hcd.self.controller,
-                       ehci->periodic_size * sizeof (u32),
+                       ehci->periodic_size * sizeof(__le32),
                        &ehci->periodic_dma, 0);
        if (ehci->periodic == 0) {
                goto fail;