From: Amit Virdi Date: Thu, 16 Feb 2012 17:33:38 +0530 Subject: [U-Boot] [PATCH 4/4] USB:gadget:designware Fix memory nonalignment issue In-Reply-To: <1329393818-24552-1-git-send-email-amit.virdi@st.com> References: <1329393818-24552-1-git-send-email-amit.virdi@st.com> Message-ID: <1329393818-24552-5-git-send-email-amit.virdi@st.com> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de From: Shiraz Hashim While receiving packets from FIFO sometimes the buffer provided was nonaligned. Fix this by taking a temporary aligned buffer and then copying the content to nonaligned buffer. Signed-off-by: Shiraz Hashim Signed-off-by: Amit Virdi --- drivers/usb/gadget/designware_udc.c | 15 ++++++++++++++- 1 files changed, 14 insertions(+), 1 deletions(-) diff --git a/drivers/usb/gadget/designware_udc.c b/drivers/usb/gadget/designware_udc.c index d4b53a2..878123c 100644 --- a/drivers/usb/gadget/designware_udc.c +++ b/drivers/usb/gadget/designware_udc.c @@ -202,6 +202,7 @@ static int usbgetpckfromfifo(int epNum, u8 *bufp, u32 len) u32 i, nw, nb; u32 *wrdp; u8 *bytp; + u32 tmp[128]; if (readl(&udc_regs_p->dev_stat) & DEV_STAT_RXFIFO_EMPTY) return -1; @@ -209,7 +210,12 @@ static int usbgetpckfromfifo(int epNum, u8 *bufp, u32 len) nw = len / sizeof(u32); nb = len % sizeof(u32); - wrdp = (u32 *)bufp; + /* use tmp buf if bufp is not word aligned */ + if ((int)bufp & 0x3) + wrdp = (u32 *)&tmp[0]; + else + wrdp = (u32 *)bufp; + for (i = 0; i < nw; i++) { writel(readl(fifo_ptr), wrdp); wrdp++; @@ -223,6 +229,13 @@ static int usbgetpckfromfifo(int epNum, u8 *bufp, u32 len) } readl(&outep_regs_p[epNum].write_done); + /* copy back tmp buffer to bufp if bufp is not word aligned */ + if ((int)bufp & 0x3) { + bytp = (u8 *)&tmp[0]; + for (i = 0; i < len; i++) + bufp[i] = bytp[i]; + } + return 0; } -- 1.7.2.2