]> git.kernelconcepts.de Git - karo-tx-uboot.git/commitdiff
mmc: add boundary check for mmc operation
authorLei Wen <leiwen@marvell.com>
Mon, 13 Sep 2010 14:07:27 +0000 (22:07 +0800)
committerWolfgang Denk <wd@denx.de>
Sat, 18 Sep 2010 21:46:24 +0000 (23:46 +0200)
Signed-off-by: Lei Wen <leiwen@marvell.com>
drivers/mmc/mmc.c

index cf4ea161b964ab36c8b4da95d9f3d209d9ca66be..23928c1356e76fcb472a138ad4e6a3e51f864f63 100644 (file)
@@ -92,6 +92,11 @@ mmc_bwrite(int dev_num, ulong start, lbaint_t blkcnt, const void*src)
 
        blklen = mmc->write_bl_len;
 
+       if ((start + blkcnt) > mmc->block_dev.lba) {
+               printf("MMC: block number 0x%x exceeds max(0x%x)",
+                       start + blkcnt, mmc->block_dev.lba);
+               return 0;
+       }
        err = mmc_set_blocklen(mmc, mmc->write_bl_len);
 
        if (err) {
@@ -219,6 +224,11 @@ static ulong mmc_bread(int dev_num, ulong start, lbaint_t blkcnt, void *dst)
        if (!mmc)
                return 0;
 
+       if ((start + blkcnt) > mmc->block_dev.lba) {
+               printf("MMC: block number 0x%x exceeds max(0x%x)",
+                       start + blkcnt, mmc->block_dev.lba);
+               return 0;
+       }
        /* We always do full block reads from the card */
        err = mmc_set_blocklen(mmc, mmc->read_bl_len);