From: Marc Kleine-Budde <mkl@pengutronix.de>
To: sha@pengutronix.de
Cc: barebox@lists.infradead.org
Subject: [PATCH 6/6] USB gadget: Fix dma memory allocations
Date: Tue, 19 Jun 2012 14:36:31 +0200 [thread overview]
Message-ID: <1340109391-22794-7-git-send-email-mkl@pengutronix.de> (raw)
In-Reply-To: <1340109391-22794-1-git-send-email-mkl@pengutronix.de>
From: Sascha Hauer <s.hauer@pengutronix.de>
This is another variant of:
USB gadget fsl: request cacheline aligned buffer
The fsl udc driver allocates a buffer for small requests. The
driver then calls dma_inv_range later on it. This buffer happens
to be not cacheline aligned which means that a dma_inv_range can
corrupt other memory around the buffer.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
[mkl: use dma_alloc]
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
drivers/usb/gadget/composite.c | 5 +++--
drivers/usb/gadget/dfu.c | 5 +++--
2 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c
index fd70e62..29848f7 100644
--- a/drivers/usb/gadget/composite.c
+++ b/drivers/usb/gadget/composite.c
@@ -24,6 +24,7 @@
#include <errno.h>
#include <usb/composite.h>
#include <asm/byteorder.h>
+#include <asm/dma.h>
#define CONFIG_USB_GADGET_VBUS_DRAW 2
@@ -867,7 +868,7 @@ composite_unbind(struct usb_gadget *gadget)
composite->unbind(cdev);
if (cdev->req) {
- kfree(cdev->req->buf);
+ dma_free(cdev->req->buf);
usb_ep_free_request(gadget->ep0, cdev->req);
}
kfree(cdev);
@@ -911,7 +912,7 @@ static int __init composite_bind(struct usb_gadget *gadget)
cdev->req = usb_ep_alloc_request(gadget->ep0);
if (!cdev->req)
goto fail;
- cdev->req->buf = malloc(USB_BUFSIZ);
+ cdev->req->buf = dma_alloc(USB_BUFSIZ);
if (!cdev->req->buf)
goto fail;
cdev->req->complete = composite_setup_complete;
diff --git a/drivers/usb/gadget/dfu.c b/drivers/usb/gadget/dfu.c
index f26c1e4..987b51c 100644
--- a/drivers/usb/gadget/dfu.c
+++ b/drivers/usb/gadget/dfu.c
@@ -56,6 +56,7 @@
#include <libbb.h>
#include <init.h>
#include <fs.h>
+#include <asm/dma.h>
#define USB_DT_DFU_SIZE 9
#define USB_DT_DFU 0x21
@@ -183,7 +184,7 @@ dfu_unbind(struct usb_configuration *c, struct usb_function *f)
if (gadget_is_dualspeed(c->cdev->gadget))
free(f->hs_descriptors);
- free(dfu->dnreq->buf);
+ dma_free(dfu->dnreq->buf);
usb_ep_free_request(c->cdev->gadget->ep0, dfu->dnreq);
free(dfu);
}
@@ -602,7 +603,7 @@ static int dfu_bind_config(struct usb_configuration *c)
dfu->dnreq = usb_ep_alloc_request(c->cdev->gadget->ep0);
if (!dfu->dnreq)
printf("usb_ep_alloc_request failed\n");
- dfu->dnreq->buf = xmalloc(CONFIG_USBD_DFU_XFER_SIZE);
+ dfu->dnreq->buf = dma_alloc(CONFIG_USBD_DFU_XFER_SIZE);
dfu->dnreq->complete = dn_complete;
dfu->dnreq->zero = 0;
--
1.7.4.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2012-06-19 12:36 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-06-19 12:36 [PATCH 0/6] fix dma memory allocations, add dma_alloc/dma_free Marc Kleine-Budde
2012-06-19 12:36 ` [PATCH 1/6] ARM mmu: don't use CONFIG_MMU to disable mmu code, there are static inline versions Marc Kleine-Budde
2012-06-19 12:36 ` [PATCH 2/6] ARM mmu: introduce dma_alloc, dma_free Marc Kleine-Budde
2012-06-19 12:36 ` [PATCH 3/6] nios: add dma_alloc, dma_free and asm/dma.h Marc Kleine-Budde
2012-06-19 12:36 ` [PATCH 4/6] blackfin, mips, openrisc, ppc, sandbox, x86: add transparent dma_alloc, dma_free inlines Marc Kleine-Budde
2012-06-19 12:36 ` [PATCH 5/6] USB gadget fsl: request cacheline aligned buffer Marc Kleine-Budde
2012-06-19 12:36 ` Marc Kleine-Budde [this message]
2012-06-19 12:42 ` [PATCH 0/6] fix dma memory allocations, add dma_alloc/dma_free Marc Kleine-Budde
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1340109391-22794-7-git-send-email-mkl@pengutronix.de \
--to=mkl@pengutronix.de \
--cc=barebox@lists.infradead.org \
--cc=sha@pengutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox