diff mbox

[RFC,3/5] mtd: do not assume oobsize is power of 2

Message ID 1313625029-19546-4-git-send-email-computersforpeace@gmail.com
State RFC
Headers show

Commit Message

Brian Norris Aug. 17, 2011, 11:50 p.m. UTC
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.

As I see it, we don't actually need these masks anyway, so kill them.

Signed-off-by: Brian Norris <computersforpeace@gmail.com>
---
 drivers/mtd/mtdchar.c |    6 ++----
 1 files changed, 2 insertions(+), 4 deletions(-)

Comments

Brian Norris Aug. 22, 2011, 8:21 p.m. UTC | #1
On Mon, Aug 22, 2011 at 1:46 AM, Artem Bityutskiy <dedekind1@gmail.com> wrote:
> On Wed, 2011-08-17 at 16:50 -0700, Brian Norris wrote:
> Once you double checked that you caught all the places which assume
> power-of-2 and do things like "x & (mtd->oobsize - 1", and once you
> confirmed that you did some basic test by running few nandwrite commands
> which involve OOB operations, I think this patch can go in
> independently.

I'll do a little more combing through the code and perform some
independent tests for this patch, then either resend an amended patch
or comment back here.

> IOW, this does need to be RFC, IMO.

I agree. I think I lumped it in with the others because I discovered
it as a byproduct of my work on the other patches in this series.

Brian
diff mbox

Patch

diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c
index 4488e9a..a0c404b 100644
--- a/drivers/mtd/mtdchar.c
+++ b/drivers/mtd/mtdchar.c
@@ -411,7 +411,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;
 	ops.datbuf = NULL;
 	ops.mode = (mfi->mode == MTD_MODE_RAW) ? MTD_OOB_RAW : MTD_OOB_PLACE;
 
@@ -422,7 +422,6 @@  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);
 	ret = mtd->write_oob(mtd, start, &ops);
 
 	if (ops.oobretlen > 0xFFFFFFFFU)
@@ -455,7 +454,7 @@  static int mtd_do_readoob(struct file *file, struct mtd_info *mtd,
 		return ret;
 
 	ops.ooblen = length;
-	ops.ooboffs = start & (mtd->oobsize - 1);
+	ops.ooboffs = start;
 	ops.datbuf = NULL;
 	ops.mode = (mfi->mode == MTD_MODE_RAW) ? MTD_OOB_RAW : MTD_OOB_PLACE;
 
@@ -466,7 +465,6 @@  static int mtd_do_readoob(struct file *file, struct mtd_info *mtd,
 	if (!ops.oobbuf)
 		return -ENOMEM;
 
-	start &= ~((uint64_t)mtd->oobsize - 1);
 	ret = mtd->read_oob(mtd, start, &ops);
 
 	if (put_user(ops.oobretlen, retp))