Patchwork [U-Boot] spl_mmc: cleanup variable types

login
register
mail settings
Submitter Peter Korsgaard
Date March 21, 2013, 2:55 p.m.
Message ID <1363877717-14546-1-git-send-email-peter.korsgaard@barco.com>
Download mbox | patch
Permalink /patch/229725/
State Accepted
Delegated to: Tom Rini
Headers show

Comments

Peter Korsgaard - March 21, 2013, 2:55 p.m.
block_read returns unsigned long, so it doesn't make sense to check for
< 0. and neither does marking the header structure as const and then
casting away the constness to load data into it.

Also cleanup some unneeded pointer casting while we're at it.

Signed-off-by: Peter Korsgaard <peter.korsgaard@barco.com>
---
 drivers/mmc/spl_mmc.c |   17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)
Tom Rini - March 21, 2013, 4:59 p.m.
On Thu, Mar 21, 2013 at 03:55:17PM +0100, Peter Korsgaard wrote:

> block_read returns unsigned long, so it doesn't make sense to check for
> < 0. and neither does marking the header structure as const and then
> casting away the constness to load data into it.
> 
> Also cleanup some unneeded pointer casting while we're at it.
> 
> Signed-off-by: Peter Korsgaard <peter.korsgaard@barco.com>

Reviewed-by: Tom Rini <trini@ti.com>
Tom Rini - May 2, 2013, 4:04 p.m.
On Thu, Mar 21, 2013 at 04:55:17AM -0000, Peter Korsgaard wrote:

> block_read returns unsigned long, so it doesn't make sense to check for
> < 0. and neither does marking the header structure as const and then
> casting away the constness to load data into it.
> 
> Also cleanup some unneeded pointer casting while we're at it.
> 
> Signed-off-by: Peter Korsgaard <peter.korsgaard@barco.com>
> Reviewed-by: Tom Rini <trini@ti.com>

Applied to u-boot/master, thanks!

Patch

diff --git a/drivers/mmc/spl_mmc.c b/drivers/mmc/spl_mmc.c
index 753c6a0..7efdcb8 100644
--- a/drivers/mmc/spl_mmc.c
+++ b/drivers/mmc/spl_mmc.c
@@ -34,8 +34,9 @@  DECLARE_GLOBAL_DATA_PTR;
 
 static void mmc_load_image_raw(struct mmc *mmc)
 {
-	u32 image_size_sectors, err;
-	const struct image_header *header;
+	unsigned long err;
+	u32 image_size_sectors;
+	struct image_header *header;
 
 	header = (struct image_header *)(CONFIG_SYS_TEXT_BASE -
 						sizeof(struct image_header));
@@ -43,9 +44,9 @@  static void mmc_load_image_raw(struct mmc *mmc)
 	/* read image header to find the image size & load address */
 	err = mmc->block_dev.block_read(0,
 			CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR, 1,
-			(void *)header);
+			header);
 
-	if (err <= 0)
+	if (err == 0)
 		goto end;
 
 	spl_parse_image_header(header);
@@ -60,8 +61,8 @@  static void mmc_load_image_raw(struct mmc *mmc)
 			image_size_sectors, (void *)spl_image.load_addr);
 
 end:
-	if (err <= 0) {
-		printf("spl: mmc blk read err - %d\n", err);
+	if (err == 0) {
+		printf("spl: mmc blk read err - %lu\n", err);
 		hang();
 	}
 }
@@ -69,7 +70,7 @@  end:
 #ifdef CONFIG_SPL_FAT_SUPPORT
 static void mmc_load_image_fat(struct mmc *mmc)
 {
-	s32 err;
+	int err;
 	struct image_header *header;
 
 	header = (struct image_header *)(CONFIG_SYS_TEXT_BASE -
@@ -83,7 +84,7 @@  static void mmc_load_image_fat(struct mmc *mmc)
 	}
 
 	err = file_fat_read(CONFIG_SPL_FAT_LOAD_PAYLOAD_NAME,
-				(u8 *)header, sizeof(struct image_header));
+				header, sizeof(struct image_header));
 	if (err <= 0)
 		goto end;