[U-Boot] [PATCH 2/5] mmc: check find_mmc_device return value
Rabin Vincent
rabin at rab.in
Sun Apr 5 10:00:53 CEST 2009
find_mmc_device returns NULL if an invalid device number is specified.
Check for this to avoid dereferencing NULL pointers.
Signed-off-by: Rabin Vincent <rabin at rab.in>
---
common/cmd_mmc.c | 9 +++++++++
drivers/mmc/mmc.c | 2 +-
2 files changed, 10 insertions(+), 1 deletions(-)
diff --git a/common/cmd_mmc.c b/common/cmd_mmc.c
index bd55ff1..039fe59 100644
--- a/common/cmd_mmc.c
+++ b/common/cmd_mmc.c
@@ -149,6 +149,9 @@ int do_mmcops(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
int dev = simple_strtoul(argv[2], NULL, 10);
struct mmc *mmc = find_mmc_device(dev);
+ if (!mmc)
+ return 1;
+
mmc_init(mmc);
return 0;
@@ -175,6 +178,9 @@ int do_mmcops(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
u32 blk = simple_strtoul(argv[4], NULL, 16);
struct mmc *mmc = find_mmc_device(dev);
+ if (!mmc)
+ return 1;
+
printf("\nMMC read: dev # %d, block # %d, count %d ... ",
dev, blk, cnt);
@@ -197,6 +203,9 @@ int do_mmcops(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
int blk = simple_strtoul(argv[4], NULL, 16);
+ if (!mmc)
+ return 1;
+
printf("\nMMC write: dev # %d, block # %d, count %d ... ",
dev, blk, cnt);
diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c
index 96186d9..50c197a 100644
--- a/drivers/mmc/mmc.c
+++ b/drivers/mmc/mmc.c
@@ -846,7 +846,7 @@ block_dev_desc_t *mmc_get_dev(int dev)
{
struct mmc *mmc = find_mmc_device(dev);
- return &mmc->block_dev;
+ return mmc ? &mmc->block_dev : NULL;
}
int mmc_init(struct mmc *mmc)
--
1.6.2.1
More information about the U-Boot
mailing list