mtd: lart: Prevent a read from mtd->eraseregions[-1]

Linux-MTD Mailing List linux-mtd at lists.infradead.org
Sat Sep 19 14:59:02 EDT 2009


Gitweb:     http://git.infradead.org/?p=mtd-2.6.git;a=commit;h=4c1e6b2ce13b154a4a69cee220c98976f4b784df
Commit:     4c1e6b2ce13b154a4a69cee220c98976f4b784df
Parent:     f12a9473283e68ae708e9ada37cb352ea2652397
Author:     Roel Kluin <roel.kluin at gmail.com>
AuthorDate: Fri Sep 18 12:51:49 2009 -0700
Committer:  David Woodhouse <David.Woodhouse at intel.com>
CommitDate: Sat Sep 19 11:18:15 2009 -0700

    mtd: lart: Prevent a read from mtd->eraseregions[-1]
    
    Signed-off-by: Roel Kluin <roel.kluin at gmail.com>
    Signed-off-by: Andrew Morton <akpm at linux-foundation.org>
    Signed-off-by: David Woodhouse <David.Woodhouse at intel.com>
---
 drivers/mtd/devices/lart.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/mtd/devices/lart.c b/drivers/mtd/devices/lart.c
index 578de1c..f4359fe 100644
--- a/drivers/mtd/devices/lart.c
+++ b/drivers/mtd/devices/lart.c
@@ -393,7 +393,8 @@ static int flash_erase (struct mtd_info *mtd,struct erase_info *instr)
 	* erase range is aligned with the erase size which is in
 	* effect here.
 	*/
-   if (instr->addr & (mtd->eraseregions[i].erasesize - 1)) return (-EINVAL);
+   if (i < 0 || (instr->addr & (mtd->eraseregions[i].erasesize - 1)))
+      return -EINVAL;
 
    /* Remember the erase region we start on */
    first = i;
@@ -409,7 +410,8 @@ static int flash_erase (struct mtd_info *mtd,struct erase_info *instr)
    i--;
 
    /* is the end aligned on a block boundary? */
-   if ((instr->addr + instr->len) & (mtd->eraseregions[i].erasesize - 1)) return (-EINVAL);
+   if (i < 0 || ((instr->addr + instr->len) & (mtd->eraseregions[i].erasesize - 1)))
+      return -EINVAL;
 
    addr = instr->addr;
    len = instr->len;



More information about the linux-mtd-cvs mailing list