]> git.karo-electronics.de Git - linux-beck.git/commitdiff
mtd: do not assume oobsize is power of 2
authorBrian Norris <computersforpeace@gmail.com>
Wed, 24 Aug 2011 00:17:32 +0000 (17:17 -0700)
committerArtem Bityutskiy <artem.bityutskiy@intel.com>
Sun, 11 Sep 2011 12:02:17 +0000 (15:02 +0300)
Previous generations of MTDs all used OOB sizes that were powers of 2,
(e.g., 64, 128). However, newer generations of flash, especially NAND,
use irregular OOB sizes that are not powers of 2 (e.g., 218, 224, 448).
This means we cannot use masks like "mtd->oobsize - 1" to assume that we
will get a proper bitmask for OOB operations.

These masks are really only intended to hide the "page" portion of the
offset, leaving any OOB offset intact, so a masking with the writesize
(which *is* always a power of 2) is valid and makes more sense.

This has been tested for read/write of NAND devices (nanddump/nandwrite)
using nandsim and actual NAND flash.

Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@intel.com>
drivers/mtd/mtdchar.c

index a75d55577e49d20383a8ad14908ceda3d2ad2321..b206254751329a47f34fcfa8550d03993950d014 100644 (file)
@@ -410,7 +410,7 @@ static int mtd_do_writeoob(struct file *file, struct mtd_info *mtd,
                return ret;
 
        ops.ooblen = length;
-       ops.ooboffs = start & (mtd->oobsize - 1);
+       ops.ooboffs = start & (mtd->writesize - 1);
        ops.datbuf = NULL;
        ops.mode = MTD_OOB_PLACE;
 
@@ -421,7 +421,7 @@ static int mtd_do_writeoob(struct file *file, struct mtd_info *mtd,
        if (IS_ERR(ops.oobbuf))
                return PTR_ERR(ops.oobbuf);
 
-       start &= ~((uint64_t)mtd->oobsize - 1);
+       start &= ~((uint64_t)mtd->writesize - 1);
        ret = mtd->write_oob(mtd, start, &ops);
 
        if (ops.oobretlen > 0xFFFFFFFFU)
@@ -452,7 +452,7 @@ static int mtd_do_readoob(struct mtd_info *mtd, uint64_t start,
                return ret;
 
        ops.ooblen = length;
-       ops.ooboffs = start & (mtd->oobsize - 1);
+       ops.ooboffs = start & (mtd->writesize - 1);
        ops.datbuf = NULL;
        ops.mode = MTD_OOB_PLACE;
 
@@ -463,7 +463,7 @@ static int mtd_do_readoob(struct mtd_info *mtd, uint64_t start,
        if (!ops.oobbuf)
                return -ENOMEM;
 
-       start &= ~((uint64_t)mtd->oobsize - 1);
+       start &= ~((uint64_t)mtd->writesize - 1);
        ret = mtd->read_oob(mtd, start, &ops);
 
        if (put_user(ops.oobretlen, retp))