[U-Boot] [PATCH 2/3] mmc: add boundary check for mmc operation

Lei Wen leiwen at marvell.com
Tue Sep 7 14:32:08 CEST 2010


Signed-off-by: Lei Wen <leiwen at marvell.com>
---
 drivers/mmc/mmc.c |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c
index 5cc1904..9a50b2f 100644
--- a/drivers/mmc/mmc.c
+++ b/drivers/mmc/mmc.c
@@ -134,6 +134,10 @@ mmc_bwrite(int dev_num, ulong start, lbaint_t blkcnt, const void*src)
 	if (!mmc)
 		return -1;
 
+	if (start > mmc->block_dev.lba || (start + blkcnt) > mmc->block_dev.lba) {
+		printf("\noperation excceed mmc boudary..\n");
+		return 0;
+	}
 	err = mmc_set_blocklen(mmc, mmc->write_bl_len);
 	if (err) {
 		printf("set write bl len failed\n\r");
@@ -236,6 +240,10 @@ static ulong mmc_bread(int dev_num, ulong start, lbaint_t blkcnt, void *dst)
 	if (!mmc)
 		return 0;
 
+	if (start > mmc->block_dev.lba || (start + blkcnt) > mmc->block_dev.lba) {
+		printf("\noperation excceed mmc boudary..\n");
+		return 0;
+	}
 	/* We always do full block reads from the card */
 	err = mmc_set_blocklen(mmc, mmc->read_bl_len);
 
-- 
1.7.0.4



More information about the U-Boot mailing list