Skip to contentSkip to conversation

mmc: add boundary check for mmc operation

PATCH New Lei Wen 3 participants 5 messages Sep 13, 2010 MMC, SD and SDIO

lore
Share & tools
lore

Lei Wen

author
#0 lore raw

PATCH 1/2 mmc: add boundary check for mmc operation

---
 drivers/mmc/mmc.c |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)
drivers/mmc/mmc.c +10 -0
index cf4ea16..5ff1c54 100644
@@ -92,6 +92,11 @@ mmc_bwrite(int dev_num, ulong start, lbaint_t blkcnt, const void*src)
 
 	blklen = mmc->write_bl_len;
 
+	if (start > mmc->block_dev.lba || (start + blkcnt) > mmc->block_dev.lba) {
+		puts("operation exceed mmc boundary..\n
+		     This devices only have 0x%x blocks\n", 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 > mmc->block_dev.lba || (start + blkcnt) > mmc->block_dev.lba) {
+		puts("operation exceed mmc boundary..\n
+		     This devices only have 0x%x blocks\n", mmc->block_dev.lba);
+		return 0;
+	}
 	/* We always do full block reads from the card */
 	err = mmc_set_blocklen(mmc, mmc->read_bl_len);
 
Signature · 1 line
1.7.0.4
author
#1 lore raw

PATCH 2/2 mmc: print out avaible partition table

---
 common/cmd_mmc.c |   20 ++++++++++++++++++++
 disk/part.c      |    3 +++
 2 files changed, 23 insertions(+), 0 deletions(-)
common/cmd_mmc.c +20 -0
index c0b30d8..fe04f8d 100644
@@ -154,6 +154,25 @@ int do_mmcops(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 			mmc_init(mmc);
 
 			return 0;
+		} else if (strncmp(argv[1], "part", 4) == 0) {
+			int dev = simple_strtoul(argv[2], NULL, 10);
+			block_dev_desc_t *mmc_dev;
+			struct mmc *mmc = find_mmc_device(dev);
+
+			if (!mmc) {
+				puts("no mmc devices available\n");
+				return 1;
+			}
+			mmc_init(mmc);
+			mmc_dev = mmc_get_dev(dev);
+			if (mmc_dev != NULL &&
+					mmc_dev->type != DEV_TYPE_UNKNOWN) {
+				print_part(mmc_dev);
+				return 0;
+			}
+
+			puts("get mmc type error!\n");
+			return 1;
 		}
 
 	case 0:
@@ -230,5 +249,6 @@ U_BOOT_CMD(
 	"read <device num> addr blk# cnt\n"
 	"mmc write <device num> addr blk# cnt\n"
 	"mmc rescan <device num>\n"
+	"mmc part <device num>- lists avaiable partition on mmc\n"
 	"mmc list - lists available devices");
 #endif
disk/part.c +3 -0
index 3ba88c7..1806fe6 100644
@@ -364,6 +364,9 @@ static void print_part_header (const char *type, block_dev_desc_t * dev_desc)
 	case IF_TYPE_DOC:
 		puts ("DOC");
 		break;
+	case IF_TYPE_MMC:
+		puts ("MMC");
+		break;
 	default:
 		puts ("UNKNOWN");
 		break;
Signature · 1 line
1.7.0.4
#2 lore raw

PATCH 2/2 mmc: print out avaible partition table

Hello.

Quoted 17 lines · Lei Wen
---
  common/cmd_mmc.c |   20 ++++++++++++++++++++
  disk/part.c      |    3 +++
  2 files changed, 23 insertions(+), 0 deletions(-)
common/cmd_mmc.c +3 -0
index c0b30d8..fe04f8d 100644
@@ -154,6 +154,25 @@ int do_mmcops(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  			mmc_init(mmc);
 
  			return 0;
+		} else if (strncmp(argv[1], "part", 4) == 0) {
+			int dev = simple_strtoul(argv[2], NULL, 10);
+			block_dev_desc_t *mmc_dev;

common/cmd_mmc.c int do_mmcops(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) · line 169

Quoted 10 lines
common/cmd_mmc.c +10 -0
+			struct mmc *mmc = find_mmc_device(dev);
+
+			if (!mmc) {
+				puts("no mmc devices available\n");
+				return 1;
+			}
+			mmc_init(mmc);
+			mmc_dev = mmc_get_dev(dev);
+			if (mmc_dev != NULL &&
+					mmc_dev->type != DEV_TYPE_UNKNOWN) {

Too much indentation.

WBR, Sergei

#3 lore raw

PATCH 1/2 mmc: add boundary check for mmc operation

In reply to Lei Wen

Hello.

Quoted 10 lines · Lei Wen
---
  drivers/mmc/mmc.c |   10 ++++++++++
  1 files changed, 10 insertions(+), 0 deletions(-)
drivers/mmc/mmc.c +0 -0
index cf4ea16..5ff1c54 100644

drivers/mmc/mmc.c mmc_bwrite(int dev_num, ulong start, lbaint_t blkcnt, const void*src) · line 95

Quoted 4 lines
drivers/mmc/mmc.c +1 -0
@@ -92,6 +92,11 @@ mmc_bwrite(int dev_num, ulong start, lbaint_t blkcnt, const void*src)
 
  	blklen = mmc->write_bl_len;
 
+	if (start > mmc->block_dev.lba || (start + blkcnt) > mmc->block_dev.lba) {

The second comparison should suffice, no? Also, parens are not necessary.

drivers/mmc/mmc.c mmc_bwrite(int dev_num, ulong start, lbaint_t blkcnt, const void*src) · line 98

Quoted 3 lines
drivers/mmc/mmc.c +2 -0
+		puts("operation exceed mmc boundary..\n
+		     This devices only have 0x%x blocks\n",
 mmc->block_dev.lba);

Where's the cloging quote? String literals are not broken up like this --
this adds extra spaces to them. Should be:

		puts("operation exceed mmc boundary..\n"
		     "This devices only have 0x%x blocks\n", mmc->block_dev.lba);

drivers/mmc/mmc.c static ulong mmc_bread(int dev_num, ulong start, lbaint_t blkcnt, void *dst) · line 229

Quoted 12 lines
drivers/mmc/mmc.c +2 -0
+		return 0;
+	}
  	err = mmc_set_blocklen(mmc, mmc->write_bl_len);
 
  	if (err) {
drivers/mmc/mmc.c +3 -0
@@ -219,6 +224,11 @@ 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) {
+		puts("operation exceed mmc boundary..\n
+		     This devices only have 0x%x blocks\n", mmc->block_dev.lba);

Same comments here...

WBR, Sergei

#4 lore raw

PATCH 1/2 mmc: add boundary check for mmc operation

Quoted 16 lines · Sergei Shtylyov

Hello.

Quoted 12 lines · Lei Wen

---
?drivers/mmc/mmc.c | ? 10 ++++++++++
?1 files changed, 10 insertions(+), 0 deletions(-)

drivers/mmc/mmc.c +0 -0
index cf4ea16..5ff1c54 100644
@@ -92,6 +92,11 @@ mmc_bwrite(int dev_num, ulong start, lbaint_t blkcnt,
 const void*src)
 
Quoted 6 lines

drivers/mmc/mmc.c mmc_bwrite(int dev_num, ulong start, lbaint_t blkcnt, · line 97

Quoted 4 lines
drivers/mmc/mmc.c +1 -0
 ? ? ? ?blklen = mmc->write_bl_len;
 
+ ? ? ? if (start > mmc->block_dev.lba || (start + blkcnt) >
 mmc->block_dev.lba) {

? The second comparison should suffice, no? Also, parens are not necessary.

Em, that is correct.

Quoted 8 lines
Quoted 5 lines
drivers/mmc/mmc.c +2 -0
+ ? ? ? ? ? ? ? puts("operation exceed mmc boundary..\n
 
+ ? ? ? ? ? ? ? ? ?This devices only have 0x%x blocks\n",

mmc->block_dev.lba);

? Where's the cloging quote? String literals are not broken up like this -- this adds extra spaces to them. Should be:

I see...
Thanks,
Lei

Quoted 25 lines

? ? ? ? ? ? ? ?puts("operation exceed mmc boundary..\n" ? ? ? ? ? ? ? ? ? ? "This devices only have 0x%x blocks\n", mmc->block_dev.lba);

Quoted 6 lines

+ ? ? ? ? ? ? ? return 0;
+ ? ? ? }
? ? ? ?err = mmc_set_blocklen(mmc, mmc->write_bl_len);

? ? ? ?if (err) {

drivers/mmc/mmc.c static ulong mmc_bread(int dev_num, ulong start, · line 232

Quoted 9 lines
drivers/mmc/mmc.c +3 -0
@@ -219,6 +224,11 @@ 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) {
+ ? ? ? ? ? ? ? puts("operation exceed mmc boundary..\n
+ ? ? ? ? ? ? ? ? ? ?This devices only have 0x%x blocks\n",
 mmc->block_dev.lba);

? Same comments here...

WBR, Sergei