Skip to content

Commit

Permalink
mtd: nand: use usual return values for the ->erase() hook
Browse files Browse the repository at this point in the history
Avoid using specific defined values for checking returned status of the
->erase() hook. Instead, use usual negative error values on failure,
zero otherwise.

Signed-off-by: Miquel Raynal <miquel.raynal@free-electrons.com>
Acked-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
  • Loading branch information
Miquel Raynal authored and Boris Brezillon committed Dec 1, 2017
1 parent 8a8c8ba commit eb94555
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion drivers/mtd/nand/denali.c
Original file line number Diff line number Diff line change
Expand Up @@ -951,7 +951,7 @@ static int denali_erase(struct mtd_info *mtd, int page)
irq_status = denali_wait_for_irq(denali,
INTR__ERASE_COMP | INTR__ERASE_FAIL);

return irq_status & INTR__ERASE_COMP ? 0 : NAND_STATUS_FAIL;
return irq_status & INTR__ERASE_COMP ? 0 : -EIO;
}

static int denali_setup_data_interface(struct mtd_info *mtd, int chipnr,
Expand Down
7 changes: 6 additions & 1 deletion drivers/mtd/nand/docg4.c
Original file line number Diff line number Diff line change
Expand Up @@ -900,6 +900,7 @@ static int docg4_erase_block(struct mtd_info *mtd, int page)
struct docg4_priv *doc = nand_get_controller_data(nand);
void __iomem *docptr = doc->virtadr;
uint16_t g4_page;
int status;

dev_dbg(doc->dev, "%s: page %04x\n", __func__, page);

Expand Down Expand Up @@ -939,7 +940,11 @@ static int docg4_erase_block(struct mtd_info *mtd, int page)
poll_status(doc);
write_nop(docptr);

return nand->waitfunc(mtd, nand);
status = nand->waitfunc(mtd, nand);
if (status < 0)
return status;

return status & NAND_STATUS_FAIL ? -EIO : 0;
}

static int write_page(struct mtd_info *mtd, struct nand_chip *nand,
Expand Down
10 changes: 8 additions & 2 deletions drivers/mtd/nand/nand_base.c
Original file line number Diff line number Diff line change
Expand Up @@ -2989,11 +2989,17 @@ static int nand_write_oob(struct mtd_info *mtd, loff_t to,
static int single_erase(struct mtd_info *mtd, int page)
{
struct nand_chip *chip = mtd_to_nand(mtd);
int status;

/* Send commands to erase a block */
chip->cmdfunc(mtd, NAND_CMD_ERASE1, -1, page);
chip->cmdfunc(mtd, NAND_CMD_ERASE2, -1, -1);

return chip->waitfunc(mtd, chip);
status = chip->waitfunc(mtd, chip);
if (status < 0)
return status;

return status & NAND_STATUS_FAIL ? -EIO : 0;
}

/**
Expand Down Expand Up @@ -3077,7 +3083,7 @@ int nand_erase_nand(struct mtd_info *mtd, struct erase_info *instr,
status = chip->erase(mtd, page & chip->pagemask);

/* See if block erase succeeded */
if (status & NAND_STATUS_FAIL) {
if (status) {
pr_debug("%s: failed erase, page 0x%08x\n",
__func__, page);
instr->state = MTD_ERASE_FAILED;
Expand Down

0 comments on commit eb94555

Please sign in to comment.