Skip to contentSkip to conversation

UBI: Ensure index is positive

PATCH In review Roel Kluin 2 participants 2 messages Nov 3, 2009 – Nov 11, 2009

Subsystems (2)
lore
Share & tools
lore

Roel Kluin

author
#0 lore raw

PATCH 1/1 UBI: Ensure index is positive

The index is signed, make sure it is not negative
when we read the array element.

---
 drivers/mtd/mtdcore.c      |    2 +-
 drivers/mtd/nand/fsl_upm.c |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/mtd/mtdcore.c +1 -1
index 467a4f1..c356c0a 100644
@@ -447,7 +447,7 @@ struct mtd_info *get_mtd_device(struct mtd_info *mtd, int num)
 		for (i=0; i< MAX_MTD_DEVICES; i++)
 			if (mtd_table[i] == mtd)
 				ret = mtd_table[i];
-	} else if (num < MAX_MTD_DEVICES) {
+	} else if (num >= 0 && num < MAX_MTD_DEVICES) {
 		ret = mtd_table[num];
 		if (mtd && mtd != ret)
 			ret = NULL;
drivers/mtd/nand/fsl_upm.c +1 -1
index d120cd8..071a60c 100644
@@ -112,7 +112,7 @@ static void fun_select_chip(struct mtd_info *mtd, int mchip_nr)
 
 	if (mchip_nr == -1) {
 		chip->cmd_ctrl(mtd, NAND_CMD_NONE, 0 | NAND_CTRL_CHANGE);
-	} else if (mchip_nr >= 0) {
+	} else if (mchip_nr >= 0 && mchip_nr < NAND_MAX_CHIPS) {
 		fun->mchip_number = mchip_nr;
 		chip->IO_ADDR_R = fun->io_base + fun->mchip_offsets[mchip_nr];
 		chip->IO_ADDR_W = chip->IO_ADDR_R;
#1 lore raw
Quoted 4 lines · Roel Kluin

The index is signed, make sure it is not negative
when we read the array element.

This is not UBI, this is mtd. I've amended the subject and pushed this patch to my l2-mtd-2.6, thanks.

Signature · 2 lines
Best Regards,
Artem Bityutskiy (Артём Битюцкий)