omap2 : bug in omap_wait

Matthieu CASTET matthieu.castet at parrot.com
Fri Jun 10 04:33:09 EDT 2011


Hi,

omap nand driver implement the nand.waitfunc[1] but it is buggy and can lead to
 nand write/erase error :
- status = NAND_STATUS_FAIL
- timeo is computed
- thread is preempted
- timeo is expired and we never enter the loop
- we return NAND_STATUS_FAIL, even if the real status is okay.

The correct behavior is to read again the status after the loop like in nand_wait.


BTW why omap2 driver doesn't use nand_wait ?

Matthieu

[1]
static int omap_wait(struct mtd_info *mtd, struct nand_chip *chip)
{
    struct nand_chip *this = mtd->priv;
    struct omap_nand_info *info = container_of(mtd, struct omap_nand_info,
                            mtd);
    unsigned long timeo = jiffies;
    int status = NAND_STATUS_FAIL, state = this->state;

    if (state == FL_ERASING)
        timeo += (HZ * 400) / 1000;
    else
        timeo += (HZ * 20) / 1000;

    gpmc_nand_write(info->gpmc_cs,
            GPMC_NAND_COMMAND, (NAND_CMD_STATUS & 0xFF));
    while (time_before(jiffies, timeo)) {
        status = gpmc_nand_read(info->gpmc_cs, GPMC_NAND_DATA);
        if (status & NAND_STATUS_READY)
            break;
        cond_resched();
    }
    return status;
}



More information about the linux-mtd mailing list