mtd: Initialize ->fail_addr early in mtd_erase()
authorBoris Brezillon <boris.brezillon@bootlin.com>
Mon, 12 Feb 2018 21:03:07 +0000 (22:03 +0100)
committerBoris Brezillon <boris.brezillon@bootlin.com>
Thu, 15 Mar 2018 16:25:05 +0000 (17:25 +0100)
mtd_erase() can return an error before ->fail_addr is initialized to
MTD_FAIL_ADDR_UNKNOWN. Move this initialization at the very beginning
of the function.

Signed-off-by: Boris Brezillon <boris.brezillon@bootlin.com>
Reviewed-by: Richard Weinberger <richard@nod.at>
drivers/mtd/mtdcore.c

index a1c9452..c87859f 100644 (file)
@@ -953,6 +953,8 @@ EXPORT_SYMBOL_GPL(__put_mtd_device);
  */
 int mtd_erase(struct mtd_info *mtd, struct erase_info *instr)
 {
+       instr->fail_addr = MTD_FAIL_ADDR_UNKNOWN;
+
        if (!mtd->erasesize || !mtd->_erase)
                return -ENOTSUPP;
 
@@ -961,7 +963,6 @@ int mtd_erase(struct mtd_info *mtd, struct erase_info *instr)
        if (!(mtd->flags & MTD_WRITEABLE))
                return -EROFS;
 
-       instr->fail_addr = MTD_FAIL_ADDR_UNKNOWN;
        if (!instr->len) {
                instr->state = MTD_ERASE_DONE;
                mtd_erase_callback(instr);