mtd: ensure index is positive

Linux-MTD Mailing List linux-mtd at lists.infradead.org
Mon Nov 30 05:59:02 EST 2009


Gitweb:     http://git.infradead.org/?p=mtd-2.6.git;a=commit;h=35016dd7e92cf0eb5ae2e811445dd52320c348d0
Commit:     35016dd7e92cf0eb5ae2e811445dd52320c348d0
Parent:     61c3506c2cabe58bcdfe438d1e57b62994db1616
Author:     Roel Kluin <roel.kluin at gmail.com>
AuthorDate: Tue Nov 3 20:49:18 2009 +0100
Committer:  David Woodhouse <David.Woodhouse at intel.com>
CommitDate: Mon Nov 30 09:50:46 2009 +0000

    mtd: ensure index is positive
    
    The index is signed, make sure it is not negative
    when we read the array element.
    
    Signed-off-by: Roel Kluin <roel.kluin at gmail.com>
    Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy at nokia.com>
    Signed-off-by: David Woodhouse <David.Woodhouse at intel.com>
---
 drivers/mtd/mtdcore.c      |    2 +-
 drivers/mtd/nand/fsl_upm.c |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
index 467a4f1..c356c0a 100644
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
@@ -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;
diff --git a/drivers/mtd/nand/fsl_upm.c b/drivers/mtd/nand/fsl_upm.c
index d120cd8..071a60c 100644
--- a/drivers/mtd/nand/fsl_upm.c
+++ b/drivers/mtd/nand/fsl_upm.c
@@ -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;



More information about the linux-mtd-cvs mailing list