mmc: add boundary check for mmc operation
Signed-off-by: Lei Wen <leiwen@marvell.com>
diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c
index cf4ea16..23928c1 100644
--- a/drivers/mmc/mmc.c
+++ b/drivers/mmc/mmc.c
@@ -92,6 +92,11 @@
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 @@
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);