Re: [PATCH 1/1] mtd: nand: add check for out of page read

From: Artem Bityutskiy
Date: Sun Dec 19 2010 - 11:54:28 EST


On Wed, 2010-12-15 at 09:55 +0800, Jason Liu wrote:
> > /* Do not allow reads past end of device */
> > if (unlikely(from >= mtd->size ||
> > ops->ooboffs + readlen > ((mtd->size >> chip->page_shift) -
> > (from >> chip->page_shift)) * len)) {
> > DEBUG(MTD_DEBUG_LEVEL0, "%s: Attempt read beyond end "
> > "of device\n", __func__);
> > return -EINVAL;
> > }
>
> Here the mtd->size in nand_base.c should be the NAND flash chip size,

I think this is partition size as well.

> while in nand_oobtest,
>
> /* Attempt to read off end of device */
> ops.mode = MTD_OOB_AUTO;
> ops.len = 0;
> ops.retlen = 0;
> ops.ooblen = mtd->ecclayout->oobavail;
> ops.oobretlen = 0;
> ops.ooboffs = 1;
> ops.datbuf = NULL;
> ops.oobbuf = readbuf;
> printk(PRINT_PREF "attempting to read past end of device\n");
> printk(PRINT_PREF "an error is expected...\n");
> err = mtd->read_oob(mtd, mtd->size - mtd->writesize, &ops);
> if (err) {
> printk(PRINT_PREF "error occurred as expected\n");
> err = 0;
> } else {
> printk(PRINT_PREF "error: read past end of device\n");
> errcnt += 1;
> }
> }
>
> here, mtd->size is mtd partition size right? when the mtd partition is
> not the last MTD partition, the error will happen.

I think this is the same in both. Try to debug this with printks().

>
> I have tested on real NAND, while not on nandsim.

Please, try to reproduce this with nandsim as well, and if it works, try
to find out why (using printk debugging)

--
Best Regards,
Artem Bityutskiy (ÐÐÑÑÑÐÐÐ ÐÑÑÑÐ)

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/