usb: gadget: fsl_udc: Use dma_alloc_coherent to allocate the status buffer
authorBenoit Goby <benoit@android.com>
Fri, 24 Sep 2010 00:58:55 +0000 (17:58 -0700)
committerColin Cross <ccross@android.com>
Wed, 6 Oct 2010 23:28:51 +0000 (16:28 -0700)
Change-Id: I7c17b7f8a8b89c6a687f6e2604542dabecc4cfa7
Signed-off-by: Benoit Goby <benoit@android.com>
drivers/usb/gadget/fsl_udc_core.c

index 0a51f643c1cb597015e13aec575fe6def3130b9e..e65a4d22bbdd978c05864f1eee273fb395c72e1c 100644 (file)
@@ -57,6 +57,7 @@
 #define        DRIVER_VERSION  "Apr 20, 2007"
 
 #define        DMA_ADDR_INVALID        (~(dma_addr_t)0)
+#define        STATUS_BUFFER_SIZE      8
 
 #ifdef CONFIG_ARCH_TEGRA
 static const char driver_name[] = "fsl-tegra-udc";
@@ -2273,8 +2274,10 @@ static int fsl_proc_read(char *page, char **start, off_t off, int count,
 static void fsl_udc_release(struct device *dev)
 {
        complete(udc_controller->done);
+#ifndef CONFIG_ARCH_TEGRA
        dma_free_coherent(dev->parent, udc_controller->ep_qh_size,
                        udc_controller->ep_qh, udc_controller->ep_qh_dma);
+#endif
        kfree(udc_controller);
 }
 
@@ -2331,8 +2334,17 @@ static int __init struct_udc_setup(struct fsl_udc *udc,
        udc->status_req = container_of(fsl_alloc_request(NULL, GFP_KERNEL),
                        struct fsl_req, req);
        /* allocate a small amount of memory to get valid address */
-       udc->status_req->req.buf = kmalloc(8, GFP_KERNEL);
-       udc->status_req->req.dma = virt_to_phys(udc->status_req->req.buf);
+       udc->status_req->req.buf = dma_alloc_coherent(&pdev->dev,
+                               STATUS_BUFFER_SIZE, &udc->status_req->req.dma,
+                               GFP_KERNEL);
+       if (!udc->status_req->req.buf) {
+               ERR("alloc status_req buffer failed\n");
+#ifndef CONFIG_ARCH_TEGRA
+               dma_free_coherent(&pdev->dev, size, udc->ep_qh, udc->ep_qh_dma);
+#endif
+               kfree(udc->eps);
+               return -ENOMEM;
+       }
 
        udc->resume_state = USB_STATE_NOTATTACHED;
        udc->usb_state = USB_STATE_POWERED;
@@ -2592,7 +2604,9 @@ static int __exit fsl_udc_remove(struct platform_device *pdev)
        remove_proc_file();
 
        /* Free allocated memory */
-       kfree(udc_controller->status_req->req.buf);
+       dma_free_coherent(&pdev->dev, STATUS_BUFFER_SIZE,
+                               udc_controller->status_req->req.buf,
+                               udc_controller->status_req->req.dma);
        kfree(udc_controller->status_req);
        kfree(udc_controller->eps);