/* Return: 0 in case of success, a negative error code otherwise.  */
int nanddev_mtd_erase(struct mtd_info *mtd, struct erase_info *einfo)
/* Return: 0 in case of success, a negative error code otherwise.  */
int nanddev_mtd_erase(struct mtd_info *mtd, struct erase_info *einfo)
{
	struct nand_device *nand = mtd_to_nanddev(mtd);
	struct nand_pos pos, last;
	int ret;
	nanddev_offs_to_pos(nand, einfo->addr, &pos);
	nanddev_offs_to_pos(nand, einfo->addr + einfo->len - 1, &last);
	while (nanddev_pos_cmp(&pos, &last) <= 0) {
		ret = nanddev_erase(nand, &pos);
		if (ret) {
			einfo->fail_addr = nanddev_pos_to_offs(nand, &pos);
			return ret;
		}
		nanddev_pos_next_eraseblock(nand, &pos);
	}
	return 0;
}