diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c index e29c1da..4ebfe54 100644 --- a/drivers/mtd/nand/nand_base.c +++ b/drivers/mtd/nand/nand_base.c @@ -905,6 +905,8 @@ static int nand_read_page_syndrome(struct mtd_info *mtd, struct nand_chip *chip, static uint8_t *nand_transfer_oob(struct nand_chip *chip, uint8_t *oob, struct mtd_oob_ops *ops, size_t len) { + int i; + switch(ops->mode) { case MTD_OOB_PLACE: @@ -917,20 +919,21 @@ static uint8_t *nand_transfer_oob(struct nand_chip *chip, uint8_t *oob, uint32_t boffs = 0, roffs = ops->ooboffs; size_t bytes = 0; - for(; free->length && len; free++, len -= bytes) { + for (i = 0; i < MTD_MAX_OOBFREE_ENTRIES && + free[i].length && len; i++, len -= bytes) { /* Read request not from offset 0 ? */ if (unlikely(roffs)) { - if (roffs >= free->length) { - roffs -= free->length; + if (roffs >= free[i].length) { + roffs -= free[i].length; continue; } - boffs = free->offset + roffs; + boffs = free[i].offset + roffs; bytes = min_t(size_t, len, - (free->length - roffs)); + (free[i].length - roffs)); roffs = 0; } else { - bytes = min_t(size_t, len, free->length); - boffs = free->offset; + bytes = min_t(size_t, len, free[i].length); + boffs = free[i].offset; } memcpy(oob, chip->oob_poi + boffs, bytes); oob += bytes; @@ -1570,6 +1573,7 @@ static uint8_t *nand_fill_oob(struct nand_chip *chip, uint8_t *oob, struct mtd_oob_ops *ops) { size_t len = ops->ooblen; + int i; switch(ops->mode) { @@ -1583,20 +1587,21 @@ static uint8_t *nand_fill_oob(struct nand_chip *chip, uint8_t *oob, uint32_t boffs = 0, woffs = ops->ooboffs; size_t bytes = 0; - for(; free->length && len; free++, len -= bytes) { + for (i = 0; i < MTD_MAX_OOBFREE_ENTRIES && + free[i].length && len; i++, len -= bytes) { /* Write request not from offset 0 ? */ if (unlikely(woffs)) { - if (woffs >= free->length) { - woffs -= free->length; + if (woffs >= free[i].length) { + woffs -= free[i].length; continue; } - boffs = free->offset + woffs; + boffs = free[i].offset + woffs; bytes = min_t(size_t, len, - (free->length - woffs)); + (free[i].length - woffs)); woffs = 0; } else { - bytes = min_t(size_t, len, free->length); - boffs = free->offset; + bytes = min_t(size_t, len, free[i].length); + boffs = free[i].offset; } memcpy(chip->oob_poi + boffs, oob, bytes); oob += bytes; @@ -2525,7 +2530,7 @@ int nand_scan_tail(struct mtd_info *mtd) * the out of band area */ chip->ecc.layout->oobavail = 0; - for (i = 0; chip->ecc.layout->oobfree[i].length; i++) + for (i = 0; i < MTD_MAX_OOBFREE_ENTRIES; i++) chip->ecc.layout->oobavail += chip->ecc.layout->oobfree[i].length; mtd->oobavail = chip->ecc.layout->oobavail;