Fedora kernel-2.6.17-1.2142_FC4 patched with stable patch-2.6.17.4-vs2.0.2-rc26.diff
[linux-2.6.git] / drivers / usb / host / ehci-mem.c
index 5f93816..766061e 100644 (file)
  * No memory seen by this driver is pageable.
  */
 
-/*-------------------------------------------------------------------------*/
-/* 
- * Allocator / cleanup for the per device structure
- * Called by hcd init / removal code
- */
-static struct usb_hcd *ehci_hcd_alloc (void)
-{
-       struct ehci_hcd *ehci;
-
-       ehci = (struct ehci_hcd *)
-               kmalloc (sizeof (struct ehci_hcd), GFP_KERNEL);
-       if (ehci != 0) {
-               memset (ehci, 0, sizeof (struct ehci_hcd));
-               ehci->hcd.product_desc = "EHCI Host Controller";
-               return &ehci->hcd;
-       }
-       return 0;
-}
-
-static void ehci_hcd_free (struct usb_hcd *hcd)
-{
-       kfree (hcd_to_ehci (hcd));
-}
-
 /*-------------------------------------------------------------------------*/
 
 /* Allocate the key transfer structures from the previously allocated pool */
@@ -69,13 +45,13 @@ static inline void ehci_qtd_init (struct ehci_qtd *qtd, dma_addr_t dma)
        INIT_LIST_HEAD (&qtd->qtd_list);
 }
 
-static struct ehci_qtd *ehci_qtd_alloc (struct ehci_hcd *ehci, int flags)
+static struct ehci_qtd *ehci_qtd_alloc (struct ehci_hcd *ehci, gfp_t flags)
 {
        struct ehci_qtd         *qtd;
        dma_addr_t              dma;
 
        qtd = dma_pool_alloc (ehci->qtd_pool, flags, &dma);
-       if (qtd != 0) {
+       if (qtd != NULL) {
                ehci_qtd_init (qtd, dma);
        }
        return qtd;
@@ -99,11 +75,10 @@ static void qh_destroy (struct kref *kref)
        }
        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)
+static struct ehci_qh *ehci_qh_alloc (struct ehci_hcd *ehci, gfp_t flags)
 {
        struct ehci_qh          *qh;
        dma_addr_t              dma;
@@ -114,7 +89,7 @@ static struct ehci_qh *ehci_qh_alloc (struct ehci_hcd *ehci, int flags)
                return qh;
 
        memset (qh, 0, sizeof *qh);
-       kref_init(&qh->kref, qh_destroy);
+       kref_init(&qh->kref);
        qh->ehci = ehci;
        qh->qh_dma = dma;
        // INIT_LIST_HEAD (&qh->qh_list);
@@ -122,10 +97,10 @@ static struct ehci_qh *ehci_qh_alloc (struct ehci_hcd *ehci, int flags)
 
        /* dummy td enables safe urb queuing */
        qh->dummy = ehci_qtd_alloc (ehci, flags);
-       if (qh->dummy == 0) {
+       if (qh->dummy == NULL) {
                ehci_dbg (ehci, "no dummy td\n");
                dma_pool_free (ehci->qh_pool, qh, qh->qh_dma);
-               qh = 0;
+               qh = NULL;
        }
        return qh;
 }
@@ -139,7 +114,7 @@ static inline struct ehci_qh *qh_get (struct ehci_qh *qh)
 
 static inline void qh_put (struct ehci_qh *qh)
 {
-       kref_put(&qh->kref);
+       kref_put(&qh->kref, qh_destroy);
 }
 
 /*-------------------------------------------------------------------------*/
@@ -153,46 +128,45 @@ static void ehci_mem_cleanup (struct ehci_hcd *ehci)
 {
        if (ehci->async)
                qh_put (ehci->async);
-       ehci->async = 0;
+       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,
+               dma_free_coherent (ehci_to_hcd(ehci)->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;
+       kfree(ehci->pshadow);
+       ehci->pshadow = NULL;
 }
 
 /* remember to add cleanup code (above) if you add anything here */
-static int ehci_mem_init (struct ehci_hcd *ehci, int flags)
+static int ehci_mem_init (struct ehci_hcd *ehci, gfp_t flags)
 {
        int i;
 
        /* QTDs for control/bulk/intr transfers */
        ehci->qtd_pool = dma_pool_create ("ehci_qtd", 
-                       ehci->hcd.self.controller,
+                       ehci_to_hcd(ehci)->self.controller,
                        sizeof (struct ehci_qtd),
                        32 /* byte alignment (for hw parts) */,
                        4096 /* can't cross 4K */);
@@ -202,7 +176,7 @@ static int ehci_mem_init (struct ehci_hcd *ehci, int flags)
 
        /* QHs for control/bulk/intr transfers */
        ehci->qh_pool = dma_pool_create ("ehci_qh", 
-                       ehci->hcd.self.controller,
+                       ehci_to_hcd(ehci)->self.controller,
                        sizeof (struct ehci_qh),
                        32 /* byte alignment (for hw parts) */,
                        4096 /* can't cross 4K */);
@@ -216,7 +190,7 @@ static int ehci_mem_init (struct ehci_hcd *ehci, int flags)
 
        /* ITD for high speed ISO transfers */
        ehci->itd_pool = dma_pool_create ("ehci_itd", 
-                       ehci->hcd.self.controller,
+                       ehci_to_hcd(ehci)->self.controller,
                        sizeof (struct ehci_itd),
                        32 /* byte alignment (for hw parts) */,
                        4096 /* can't cross 4K */);
@@ -226,7 +200,7 @@ static int ehci_mem_init (struct ehci_hcd *ehci, int flags)
 
        /* SITD for full/low speed split ISO transfers */
        ehci->sitd_pool = dma_pool_create ("ehci_sitd", 
-                       ehci->hcd.self.controller,
+                       ehci_to_hcd(ehci)->self.controller,
                        sizeof (struct ehci_sitd),
                        32 /* byte alignment (for hw parts) */,
                        4096 /* can't cross 4K */);
@@ -235,24 +209,20 @@ static int ehci_mem_init (struct ehci_hcd *ehci, int flags)
        }
 
        /* Hardware periodic table */
-       ehci->periodic = (u32 *)
-               dma_alloc_coherent (ehci->hcd.self.controller,
-                       ehci->periodic_size * sizeof (u32),
+       ehci->periodic = (__le32 *)
+               dma_alloc_coherent (ehci_to_hcd(ehci)->self.controller,
+                       ehci->periodic_size * sizeof(__le32),
                        &ehci->periodic_dma, 0);
-       if (ehci->periodic == 0) {
+       if (ehci->periodic == NULL) {
                goto fail;
        }
        for (i = 0; i < ehci->periodic_size; i++)
                ehci->periodic [i] = EHCI_LIST_END;
 
        /* software shadow of hardware table */
-       ehci->pshadow = kmalloc (ehci->periodic_size * sizeof (void *), flags);
-       if (ehci->pshadow == 0) {
-               goto fail;
-       }
-       memset (ehci->pshadow, 0, ehci->periodic_size * sizeof (void *));
-
-       return 0;
+       ehci->pshadow = kcalloc(ehci->periodic_size, sizeof(void *), flags);
+       if (ehci->pshadow != NULL)
+               return 0;
 
 fail:
        ehci_dbg (ehci, "couldn't init memory\n");