From patchwork Thu Feb 16 12:03:38 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Virdi X-Patchwork-Id: 141582 X-Patchwork-Delegate: marek.vasut@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 89291B6F98 for ; Thu, 16 Feb 2012 23:05:00 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 2FF7E2808A; Thu, 16 Feb 2012 13:04:43 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id wouF+nRQOBgZ; Thu, 16 Feb 2012 13:04:42 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id C815C280F8; Thu, 16 Feb 2012 13:04:20 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 3CDD32808A for ; Thu, 16 Feb 2012 13:04:14 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id EDM+3dkTmpKg for ; Thu, 16 Feb 2012 13:04:05 +0100 (CET) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from eu1sys200aog105.obsmtp.com (eu1sys200aog105.obsmtp.com [207.126.144.119]) by theia.denx.de (Postfix) with ESMTPS id B049F2808C for ; Thu, 16 Feb 2012 13:04:02 +0100 (CET) Received: from beta.dmz-ap.st.com ([138.198.100.35]) (using TLSv1) by eu1sys200aob105.postini.com ([207.126.147.11]) with SMTP ID DSNKTzzwqTibdyBoCHTwrbeYh+Q+DQ9zFsgK@postini.com; Thu, 16 Feb 2012 12:04:04 UTC Received: from zeta.dmz-ap.st.com (ns6.st.com [138.198.234.13]) by beta.dmz-ap.st.com (STMicroelectronics) with ESMTP id 03542DA; Thu, 16 Feb 2012 11:55:23 +0000 (GMT) Received: from Webmail-ap.st.com (eapex1hubcas4.st.com [10.80.176.69]) by zeta.dmz-ap.st.com (STMicroelectronics) with ESMTP id D8694510; Thu, 16 Feb 2012 12:03:49 +0000 (GMT) Received: from localhost (10.199.7.86) by Webmail-ap.st.com (10.80.176.7) with Microsoft SMTP Server (TLS) id 8.3.192.1; Thu, 16 Feb 2012 20:03:49 +0800 From: Amit Virdi To: Date: Thu, 16 Feb 2012 17:33:38 +0530 Message-ID: <1329393818-24552-5-git-send-email-amit.virdi@st.com> X-Mailer: git-send-email 1.7.2.2 In-Reply-To: <1329393818-24552-1-git-send-email-amit.virdi@st.com> References: <1329393818-24552-1-git-send-email-amit.virdi@st.com> MIME-Version: 1.0 Cc: armando.visconti@st.com, shiraz.hashim@st.com, Amit Virdi Subject: [U-Boot] [PATCH 4/4] USB:gadget:designware Fix memory nonalignment issue X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@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; }