mtd: ensure index is positive
authorRoel Kluin <roel.kluin@gmail.com>
Tue, 3 Nov 2009 19:49:18 +0000 (20:49 +0100)
committerDavid Woodhouse <David.Woodhouse@intel.com>
Mon, 30 Nov 2009 09:50:46 +0000 (09:50 +0000)
The index is signed, make sure it is not negative
when we read the array element.

Signed-off-by: Roel Kluin <roel.kluin@gmail.com>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
drivers/mtd/mtdcore.c
drivers/mtd/nand/fsl_upm.c

index 467a4f177bfb269d684029954fb1731a011a12ce..c356c0a30c3e46b82d5dca258491390494098c82 100644 (file)
@@ -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;
index d120cd8d72674919fc453870978765ebf95d9a00..071a60cb42041b4d660189a1b01223a17b081b00 100644 (file)
@@ -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;