From 3cea820b3c15e2342811a0c7a9da726eb01be519 Mon Sep 17 00:00:00 2001 From: Benoit Goby Date: Thu, 23 Sep 2010 17:58:55 -0700 Subject: [PATCH] usb: gadget: fsl_udc: Use dma_alloc_coherent to allocate the status buffer Change-Id: I7c17b7f8a8b89c6a687f6e2604542dabecc4cfa7 Signed-off-by: Benoit Goby --- drivers/usb/gadget/fsl_udc_core.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/drivers/usb/gadget/fsl_udc_core.c b/drivers/usb/gadget/fsl_udc_core.c index 0a51f643c1cb..e65a4d22bbdd 100644 --- a/drivers/usb/gadget/fsl_udc_core.c +++ b/drivers/usb/gadget/fsl_udc_core.c @@ -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); -- 2.34.1