Patchwork [U-Boot,3/5] cmd_bmp: use bmp_layout API

login
register
mail settings
Submitter Nikita Kiryanov
Date Feb. 4, 2013, 11:39 a.m.
Message ID <1359977979-28585-4-git-send-email-nikita@compulab.co.il>
Download mbox | patch
Permalink /patch/217876/
State Not Applicable
Delegated to: Wolfgang Denk
Headers show

Comments

Nikita Kiryanov - Feb. 4, 2013, 11:39 a.m.
If the BMP headers are located in unaligned addresses, accessing them
directly may lead to a data abort on some architectures. Use the safer
bmp_layout API instead.

Signed-off-by: Nikita Kiryanov <nikita@compulab.co.il>
Signed-off-by: Igor Grinberg <grinberg@compulab.co.il>
Cc: Anatolij Gustschin <agust@denx.de>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Albert ARIBAUD <albert.u.boot@aribaud.net>
Cc: Jeroen Hofstee <jeroen@myspectrum.nl>
---
 common/cmd_bmp.c |   17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)

Patch

diff --git a/common/cmd_bmp.c b/common/cmd_bmp.c
index 5a52edd..0713ba8 100644
--- a/common/cmd_bmp.c
+++ b/common/cmd_bmp.c
@@ -73,8 +73,7 @@  bmp_image_t *gunzip_bmp(unsigned long addr, unsigned long *lenp)
 	/*
 	 * Check for bmp mark 'BM'
 	 */
-	if (!((bmp->header.signature[0] == 'B') &&
-	      (bmp->header.signature[1] == 'M'))) {
+	if (!bmp_signature_valid(bmp)) {
 		free(dst);
 		return NULL;
 	}
@@ -191,8 +190,7 @@  static int bmp_info(ulong addr)
 	bmp_image_t *bmp=(bmp_image_t *)addr;
 	unsigned long len;
 
-	if (!((bmp->header.signature[0]=='B') &&
-	      (bmp->header.signature[1]=='M')))
+	if (!bmp_signature_valid(bmp))
 		bmp = gunzip_bmp(addr, &len);
 
 	if (bmp == NULL) {
@@ -200,10 +198,10 @@  static int bmp_info(ulong addr)
 		return 1;
 	}
 
-	printf("Image size    : %d x %d\n", le32_to_cpu(bmp->header.width),
-	       le32_to_cpu(bmp->header.height));
-	printf("Bits per pixel: %d\n", le16_to_cpu(bmp->header.bit_count));
-	printf("Compression   : %d\n", le32_to_cpu(bmp->header.compression));
+	printf("Image size    : %d x %d\n", bmp_get_width(bmp),
+			bmp_get_height(bmp));
+	printf("Bits per pixel: %d\n", bmp_get_bit_count(bmp));
+	printf("Compression   : %d\n", bmp_get_compression(bmp));
 
 	if ((unsigned long)bmp != addr)
 		free(bmp);
@@ -227,8 +225,7 @@  int bmp_display(ulong addr, int x, int y)
 	bmp_image_t *bmp = (bmp_image_t *)addr;
 	unsigned long len;
 
-	if (!((bmp->header.signature[0]=='B') &&
-	      (bmp->header.signature[1]=='M')))
+	if (!bmp_signature_valid(bmp))
 		bmp = gunzip_bmp(addr, &len);
 
 	if (!bmp) {