From patchwork Wed Mar 7 09:39:41 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Virdi X-Patchwork-Id: 145176 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 6B759B6EEE for ; Wed, 7 Mar 2012 20:40:41 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 1C19528097; Wed, 7 Mar 2012 10:40:30 +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 f9aWPYoqRyd1; Wed, 7 Mar 2012 10:40:30 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 99EAB280B8; Wed, 7 Mar 2012 10:40:12 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id A668E2808C for ; Wed, 7 Mar 2012 10:40:08 +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 02Nfo+zI5FWL for ; Wed, 7 Mar 2012 10:40:08 +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 eu1sys200aog104.obsmtp.com (eu1sys200aog104.obsmtp.com [207.126.144.117]) by theia.denx.de (Postfix) with ESMTPS id 2CB4D28098 for ; Wed, 7 Mar 2012 10:40:00 +0100 (CET) Received: from beta.dmz-ap.st.com ([138.198.100.35]) (using TLSv1) by eu1sys200aob104.postini.com ([207.126.147.11]) with SMTP ID DSNKT1cs7cS5CMNlFASwmXeG3vA9Et5WNs7D@postini.com; Wed, 07 Mar 2012 09:40:01 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 04B7F13C; Wed, 7 Mar 2012 09:31:29 +0000 (GMT) Received: from Webmail-ap.st.com (eapex1hubcas2.st.com [10.80.176.10]) by zeta.dmz-ap.st.com (STMicroelectronics) with ESMTP id 18A09CFB; Wed, 7 Mar 2012 09:39:55 +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; Wed, 7 Mar 2012 17:39:26 +0800 From: Amit Virdi To: Date: Wed, 7 Mar 2012 15:09:41 +0530 Message-ID: <1331113181-2193-6-git-send-email-amit.virdi@st.com> X-Mailer: git-send-email 1.7.2.2 In-Reply-To: <1331113181-2193-1-git-send-email-amit.virdi@st.com> References: <1331113181-2193-1-git-send-email-amit.virdi@st.com> MIME-Version: 1.0 Cc: marex@denx.de, Shiraz Hashim , Amit Virdi , sr@denx.de, spear-devel@list.st.com Subject: [U-Boot] [PATCH V2 5/5] 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 | 12 +++++++++++- 1 files changed, 11 insertions(+), 1 deletions(-) diff --git a/drivers/usb/gadget/designware_udc.c b/drivers/usb/gadget/designware_udc.c index 67cdb29..7e9ccde 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,10 @@ 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) + memcpy(bufp, tmp, len); + return 0; }