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 <[email protected]>
Signed-off-by: Igor Grinberg <[email protected]>
Cc: Anatolij Gustschin <[email protected]>
Cc: Wolfgang Denk <[email protected]>
Cc: Albert ARIBAUD <[email protected]>
Cc: Jeroen Hofstee <[email protected]>
---
 common/cmd_bmp.c |   17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)

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) {
-- 
1.7.10.4

_______________________________________________
U-Boot mailing list
[email protected]
http://lists.denx.de/mailman/listinfo/u-boot

Reply via email to