AW: [PATCH] [MTD] NAND: Wrong calculation of page number innand_block_bad()

Knobloch, Thomas knobloch at siemens.com
Wed May 2 08:14:25 EDT 2007


On Fri, 2007-04-27 at 19:04, Thomas Gleixner wrote:
> Can you please make this outside the else path, so we can remove same
> code in the if (getchip) path.
> 
> Please also apply the pagemask right there so we don't have it in both
> cmdfunc() calls.

I added the requested code cleanup to the original patch:

diff -auNr a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
--- a/drivers/mtd/nand/nand_base.c	2007-04-27 12:44:23.000000000
+0200
+++ b/drivers/mtd/nand/nand_base.c	2007-05-02 13:19:19.080023100
+0200
@@ -303,28 +303,27 @@
 	struct nand_chip *chip = mtd->priv;
 	u16 bad;
 
+	page = (int)(ofs >> chip->page_shift) & chip->pagemask;
+
 	if (getchip) {
-		page = (int)(ofs >> chip->page_shift);
 		chipnr = (int)(ofs >> chip->chip_shift);
 
 		nand_get_device(chip, mtd, FL_READING);
 
 		/* Select the NAND device */
 		chip->select_chip(mtd, chipnr);
-	} else
-		page = (int)ofs;
+	}
 
 	if (chip->options & NAND_BUSWIDTH_16) {
 		chip->cmdfunc(mtd, NAND_CMD_READOOB, chip->badblockpos &
0xFE,
-			      page & chip->pagemask);
+			      page);
 		bad = cpu_to_le16(chip->read_word(mtd));
 		if (chip->badblockpos & 0x1)
 			bad >>= 8;
 		if ((bad & 0xFF) != 0xff)
 			res = 1;
 	} else {
-		chip->cmdfunc(mtd, NAND_CMD_READOOB, chip->badblockpos,
-			      page & chip->pagemask);
+		chip->cmdfunc(mtd, NAND_CMD_READOOB, chip->badblockpos,
page);
 		if (chip->read_byte(mtd) != 0xff)
 			res = 1;
 	}




More information about the linux-mtd mailing list