/* TODO Check badblock */ 
/* Check if we have a bad block, we do not erase bad blocks */ if (onenand_block_checkbad(mtd, addr, 0, 0)) { printk (KERN_WARNING "onenand_erase: attempt to erase a bad block at addr 0x%08x\n", (unsigned int) addr); instr->state = MTD_ERASE_FAILED; goto erase_exit; } 
static int onenand_erase(struct mtd_info *mtd, struct erase_info *instr){	struct onenand_chip *this = mtd->priv;	unsigned int block_size;	loff_t addr;	int len;	int ret = 0;	DEBUG(MTD_DEBUG_LEVEL3, "onenand_erase: start = 0x%08x, len = %i\n", (unsigned int) instr->addr, (unsigned int) instr->len);	block_size = (1 << this->erase_shift);	/* Start address must align on block boundary */	if (unlikely(instr->addr & (block_size - 1))) {		DEBUG(MTD_DEBUG_LEVEL0, "onenand_erase: Unaligned address\n");		return -EINVAL;	}	/* Length must align on block boundary */	if (unlikely(instr->len & (block_size - 1))) {		DEBUG(MTD_DEBUG_LEVEL0, "onenand_erase: Length not block aligned\n");		return -EINVAL;	}	/* Do not allow erase past end of device */	if (unlikely((instr->len + instr->addr) > mtd->size)) {		DEBUG(MTD_DEBUG_LEVEL0, "onenand_erase: Erase past end of device\n");		return -EINVAL;	}	instr->fail_addr = 0xffffffff;	/* Grab the lock and see if the device is available */	onenand_get_device(mtd, FL_ERASING);	/* Loop throught the pages */	len = instr->len;	addr = instr->addr;	instr->state = MTD_ERASING;	while (len) {		/* TODO Check badblock */		this->command(mtd, ONENAND_CMD_ERASE, addr, block_size);		ret = this->wait(mtd, FL_ERASING);		/* Check, if it is write protected */		if (ret) {			if (ret == -EPERM)				DEBUG(MTD_DEBUG_LEVEL0, "onenand_erase: Device is write protected!!!\n");			else				DEBUG(MTD_DEBUG_LEVEL0, "onenand_erase: Failed erase, block %d\n", (unsigned) (addr >> this->erase_shift));			instr->state = MTD_ERASE_FAILED;			instr->fail_addr = addr;			goto erase_exit;		}		len -= block_size;		addr += block_size;	}	instr->state = MTD_ERASE_DONE;erase_exit:	ret = instr->state == MTD_ERASE_DONE ? 0 : -EIO;	/* Do call back function */	if (!ret)		mtd_erase_callback(instr);	/* Deselect and wake up anyone waiting on the device */	onenand_release_device(mtd);	return ret;}
10457	/local/tlutelli/issta_data/temp/c/2005_temp/2005/10457/cdc001305da4f057353911018e28f26f8f879061/onenand_base.c/buggy/drivers/mtd/onenand/onenand_base.c