From: Wolfgang Denk Date: Mon, 03 Jun 2013 20:44:52 +0200 Subject: [U-Boot] [PATCH V2] lcd: align bmp header when uncopmressing image In-Reply-To: <1370267979-17800-1-git-send-email-p.wilczek@samsung.com> References: <1369999573-15449-1-git-send-email-p.wilczek@samsung.com> <1370267979-17800-1-git-send-email-p.wilczek@samsung.com> Message-ID: <20130603184452.D85DD383069@gemini.denx.de> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de Dear Piotr Wilczek, In message <1370267979-17800-1-git-send-email-p.wilczek@samsung.com> you wrote: > When compressed image is loaded, it must be decompressed > to an aligned address + 2 to avoid unaligned access exception > on some ARM platforms. ... > - dst = malloc(CONFIG_SYS_VIDEO_LOGO_MAX_SIZE); > + dst = malloc(CONFIG_SYS_VIDEO_LOGO_MAX_SIZE + 0x04); Why + 4? This needs a comment. And please write 4 as 4, and not as 0x4 when there is no good reason for it. > + /* align to 32-bit-aligned-address + 2 */ > + if ((unsigned int)bmp % 0x04 != 0x02) > + bmp = (bmp_image_t *)((((unsigned int)dst + 0x2) & ~0x1) | 0x2); This is difficult to read and inefficient. If you want to do it manually, just write it as bmp = (bmp_image_t *)((((unsigned int)dst + 1) & ~3) + 2); [Actually adding 3 to the "malloc()" size above would be sufficient with this]. A more readable way but slightly less efficient way might be: u32_t n = (u32_t)dst; bmp = (bmp_image_t *)(ALIGN(n, 4) + 2); Best regards, Wolfgang Denk -- DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de I've got to get something inside me. Some coffee or something. And then the world will somehow be better. - Terry Pratchett, _Men at Arms_