About MTD Testing suite included in the Linux kernel.

os user gnusercn at gmail.com
Sat Dec 11 08:22:50 EST 2010


When I work on MTD testing tool (drivers/mtd/tests) included in the
Linux kernel, I found a problem.
For mtd_oobtest, I failed at the testing '4 of 5'. This testing case
will test 'reading past the device'.

Since for my Nandflash controller, no special function is provided for
reading OOB, I looked into the standard implementation 'nand_do_read_oob'.
The logic below seems a little bit confusing for me,

/* 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;

In mtd_oobtest program, the testing code looks like,

/* Attempt to read off end of device */
               ops.mode      = MTD_OOB_AUTO;
               ops.len       = 0;
               ops.retlen    = 0;
               ops.ooblen    = mtd->ecclayout->oobavail + 1;
               ops.oobretlen = 0;
               ops.ooboffs   = 0;
               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;

It seems, according to the logic in MTD testing suite, MTD should
return an error. But I do not observed any error reported.

Could anyone please have a look at the two code pieces and tell me which
side needs a modification?



More information about the linux-mtd mailing list