]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
mmc: check find_mmc_device return value
authorRabin Vincent <rabin@rab.in>
Sun, 5 Apr 2009 08:00:53 +0000 (13:30 +0530)
committerAndy Fleming <afleming@freescale.com>
Tue, 2 Jun 2009 22:18:56 +0000 (17:18 -0500)
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@rab.in>
common/cmd_mmc.c
drivers/mmc/mmc.c

index bd55ff1c77b663cbf9d1ac1d50b0243d22628e9d..039fe59c75410d79ae430e5cf7fdba5ae1625e1c 100644 (file)
@@ -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);
 
index 7791c3896e98a00461bda3d4f18bb55d599bad82..70b4130862aecdd182e93a0f814c7da661aca35c 100644 (file)
@@ -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)