From patchwork Fri Jan 10 14:31:59 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Przemyslaw Marczak X-Patchwork-Id: 309301 X-Patchwork-Delegate: promsoft@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 C31482C0096 for ; Sat, 11 Jan 2014 01:34:11 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 5443B4AB27; Fri, 10 Jan 2014 15:33:55 +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 TiVdAxSOLkVG; Fri, 10 Jan 2014 15:33:55 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 2EED24AC05; Fri, 10 Jan 2014 15:33:04 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 032F34AB9D for ; Fri, 10 Jan 2014 15:32:55 +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 rneKgqKXAm6z for ; Fri, 10 Jan 2014 15:32:50 +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 mailout4.w1.samsung.com (mailout4.w1.samsung.com [210.118.77.14]) by theia.denx.de (Postfix) with ESMTPS id 823794AADD for ; Fri, 10 Jan 2014 15:32:36 +0100 (CET) Received: from eucpsbgm1.samsung.com (unknown [203.254.199.244]) by mailout4.w1.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0MZ6003LAWE4CX50@mailout4.w1.samsung.com> for u-boot@lists.denx.de; Fri, 10 Jan 2014 14:32:28 +0000 (GMT) X-AuditID: cbfec7f4-b7f796d000005a13-42-52d0047bd7f4 Received: from eusync3.samsung.com ( [203.254.199.213]) by eucpsbgm1.samsung.com (EUCPMTA) with SMTP id 03.8C.23059.B7400D25; Fri, 10 Jan 2014 14:32:27 +0000 (GMT) Received: from AMDC1186.digital.local ([106.116.147.185]) by eusync3.samsung.com (Oracle Communications Messaging Server 7u4-23.01(7.0.4.23.0) 64bit (built Aug 10 2011)) with ESMTPA id <0MZ600K8EWDV0160@eusync3.samsung.com>; Fri, 10 Jan 2014 14:32:27 +0000 (GMT) From: Przemyslaw Marczak To: u-boot@lists.denx.de Date: Fri, 10 Jan 2014 15:31:59 +0100 Message-id: X-Mailer: git-send-email 1.7.9.5 In-reply-to: References: In-reply-to: References: <1386093806-2948-1-git-send-email-p.marczak@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmpnluLIzCtJLcpLzFFi42I5/e/4Vd1qlgtBBlP7JCyun7ezWDqjj9Vi 19/7jBY3frWxWrx5uJnRouNIC6PFjss3WCzWPVnLavF2bye7A6fH2Ts7GD36tqxiDGCK4rJJ Sc3JLEst0rdL4Mp4dfYlc8EUqYrGX0tYGxg7RbsYOTkkBEwkem/2MkLYYhIX7q1n62Lk4hAS WMoo8fPdYXaQhJBAH5PEpd1KIDabgIHEnktnmEFsEQEJiV/9VxlBGpgFrjFKfPp9GWySsECi xN7ZrUDNHBwsAqoSTQvcQMK8ArESL65tYQIJSwgoSMyZZAMS5hSwlNjY/ZQJYpWFxJfee0yY 4sUSO35OYpzAyL+AkWEVo2hqaXJBcVJ6rqFecWJucWleul5yfu4mRkjgfdnBuPiY1SFGAQ5G JR7eglnng4RYE8uKK3MPMUpwMCuJ8Nq/AgrxpiRWVqUW5ccXleakFh9iZOLglGpgFMpQU3Nb d3fx/MlPSho/B/TkM3mtEa/NXvHie3e1C8vO4nclFmLb2X9Wp9ufu3K2u1vi/vRfMcuyNfec seeomvfelPm6at71nJkc9/7N/iOQyPaG+e2GyDsX79StfNzjvrRjgwaDw5KKr8bTv+/JOhq4 bHGU76dQ+zjbG3JWG1PDP+9bK348R4mlOCPRUIu5qDgRAGBtFE4aAgAA Cc: p.wilczek@samsung.com, dh09.lee@samsung.com, jh80.chung@samsung.com, Przemyslaw Marczak Subject: [U-Boot] [PATCH v5 05/12] common: lcd.c: fix data abort exception when try to access bmp header 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: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de Changes: - le16_to_cpu() to get_unaligned_le16() - le32_to_cpu() to get_unaligned_le32() when access fields in struct bmp header. This changes avoids data abort exception caused by unaligned data access. Signed-off-by: Przemyslaw Marczak Acked-by: Anatolij Gustschin --- Changes v2: - new patch Changes v3: - common/Makefile - remove CFLAG: -mno-unaligned-access - common/lcd.c - fix data abort exception when access bmp_header Changes v4: - add Acked-by Changes v5: - none common/lcd.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/common/lcd.c b/common/lcd.c index 56bf067..aa81522 100644 --- a/common/lcd.c +++ b/common/lcd.c @@ -26,7 +26,7 @@ #endif #include #include - +#include #include #if defined(CONFIG_CPU_PXA25X) || defined(CONFIG_CPU_PXA27X) || \ @@ -777,9 +777,9 @@ static void lcd_display_rle8_bitmap(bmp_image_t *bmp, ushort *cmap, uchar *fb, int x, y; int decode = 1; - width = le32_to_cpu(bmp->header.width); - height = le32_to_cpu(bmp->header.height); - bmap = (uchar *)bmp + le32_to_cpu(bmp->header.data_offset); + width = get_unaligned_le32(&bmp->header.width); + height = get_unaligned_le32(&bmp->header.height); + bmap = (uchar *)bmp + get_unaligned_le32(&bmp->header.data_offset); x = 0; y = height - 1; @@ -900,9 +900,10 @@ int lcd_display_bitmap(ulong bmp_image, int x, int y) return 1; } - width = le32_to_cpu(bmp->header.width); - height = le32_to_cpu(bmp->header.height); - bmp_bpix = le16_to_cpu(bmp->header.bit_count); + width = get_unaligned_le32(&bmp->header.width); + height = get_unaligned_le32(&bmp->header.height); + bmp_bpix = get_unaligned_le16(&bmp->header.bit_count); + colors = 1 << bmp_bpix; bpix = NBITS(panel_info.vl_bpix); @@ -917,9 +918,7 @@ int lcd_display_bitmap(ulong bmp_image, int x, int y) /* We support displaying 8bpp BMPs on 16bpp LCDs */ if (bpix != bmp_bpix && !(bmp_bpix == 8 && bpix == 16)) { printf ("Error: %d bit/pixel mode, but BMP has %d bit/pixel\n", - bpix, - le16_to_cpu(bmp->header.bit_count)); - + bpix, get_unaligned_le16(&bmp->header.bit_count)); return 1; } @@ -956,7 +955,6 @@ int lcd_display_bitmap(ulong bmp_image, int x, int y) } } #endif - /* * BMP format for Monochrome assumes that the state of a * pixel is described on a per Bit basis, not per Byte. @@ -987,15 +985,16 @@ int lcd_display_bitmap(ulong bmp_image, int x, int y) if ((y + height) > panel_info.vl_row) height = panel_info.vl_row - y; - bmap = (uchar *) bmp + le32_to_cpu(bmp->header.data_offset); - fb = (uchar *) (lcd_base + + bmap = (uchar *)bmp + get_unaligned_le32(&bmp->header.data_offset); + fb = (uchar *)(lcd_base + (y + height - 1) * lcd_line_length + x * bpix / 8); switch (bmp_bpix) { case 1: /* pass through */ case 8: #ifdef CONFIG_LCD_BMP_RLE8 - if (le32_to_cpu(bmp->header.compression) == BMP_BI_RLE8) { + u32 compression = get_unaligned_le32(&bmp->header.compression); + if (compression == BMP_BI_RLE8) { if (bpix != 16) { /* TODO implement render code for bpix != 16 */ printf("Error: only support 16 bpix");