]> git.karo-electronics.de Git - karo-tx-linux.git/blobdiff - drivers/mtd/spi-nor/spi-nor.c
mtd: spi-nor: Check the return value from read_sr()
[karo-tx-linux.git] / drivers / mtd / spi-nor / spi-nor.c
index a38ec01a1e06d8ed1fd0cc85ccc56105e672e1b8..7e5051e604b02c368cbea20a3609506917b00882 100644 (file)
@@ -410,17 +410,13 @@ static int spi_nor_erase(struct mtd_info *mtd, struct erase_info *instr)
 
        write_disable(nor);
 
+erase_err:
        spi_nor_unlock_and_unprep(nor, SPI_NOR_OPS_ERASE);
 
-       instr->state = MTD_ERASE_DONE;
+       instr->state = ret ? MTD_ERASE_FAILED : MTD_ERASE_DONE;
        mtd_erase_callback(instr);
 
        return ret;
-
-erase_err:
-       spi_nor_unlock_and_unprep(nor, SPI_NOR_OPS_ERASE);
-       instr->state = MTD_ERASE_FAILED;
-       return ret;
 }
 
 static void stm_get_locked_range(struct spi_nor *nor, u8 sr, loff_t *ofs,
@@ -482,11 +478,13 @@ static int stm_is_locked_sr(struct spi_nor *nor, loff_t ofs, uint64_t len,
 static int stm_lock(struct spi_nor *nor, loff_t ofs, uint64_t len)
 {
        struct mtd_info *mtd = &nor->mtd;
-       u8 status_old, status_new;
+       int status_old, status_new;
        u8 mask = SR_BP2 | SR_BP1 | SR_BP0;
        u8 shift = ffs(mask) - 1, pow, val;
 
        status_old = read_sr(nor);
+       if (status_old < 0)
+               return status_old;
 
        /* SPI NOR always locks to the end */
        if (ofs + len != mtd->size) {
@@ -532,11 +530,13 @@ static int stm_lock(struct spi_nor *nor, loff_t ofs, uint64_t len)
 static int stm_unlock(struct spi_nor *nor, loff_t ofs, uint64_t len)
 {
        struct mtd_info *mtd = &nor->mtd;
-       uint8_t status_old, status_new;
+       int status_old, status_new;
        u8 mask = SR_BP2 | SR_BP1 | SR_BP0;
        u8 shift = ffs(mask) - 1, pow, val;
 
        status_old = read_sr(nor);
+       if (status_old < 0)
+               return status_old;
 
        /* Cannot unlock; would unlock larger region than requested */
        if (stm_is_locked_sr(nor, status_old, ofs - mtd->erasesize,
@@ -738,9 +738,9 @@ static const struct flash_info spi_nor_ids[] = {
        { "mx25l4005a",  INFO(0xc22013, 0, 64 * 1024,   8, SECT_4K) },
        { "mx25l8005",   INFO(0xc22014, 0, 64 * 1024,  16, 0) },
        { "mx25l1606e",  INFO(0xc22015, 0, 64 * 1024,  32, SECT_4K) },
-       { "mx25l3205d",  INFO(0xc22016, 0, 64 * 1024,  64, 0) },
+       { "mx25l3205d",  INFO(0xc22016, 0, 64 * 1024,  64, SECT_4K) },
        { "mx25l3255e",  INFO(0xc29e16, 0, 64 * 1024,  64, SECT_4K) },
-       { "mx25l6405d",  INFO(0xc22017, 0, 64 * 1024, 128, 0) },
+       { "mx25l6405d",  INFO(0xc22017, 0, 64 * 1024, 128, SECT_4K) },
        { "mx25u6435f",  INFO(0xc22537, 0, 64 * 1024, 128, SECT_4K) },
        { "mx25l12805d", INFO(0xc22018, 0, 64 * 1024, 256, 0) },
        { "mx25l12855e", INFO(0xc22618, 0, 64 * 1024, 256, 0) },
@@ -890,7 +890,7 @@ static const struct flash_info *spi_nor_read_id(struct spi_nor *nor)
                                return &spi_nor_ids[tmp];
                }
        }
-       dev_err(nor->dev, "unrecognized JEDEC id bytes: %02x, %2x, %2x\n",
+       dev_err(nor->dev, "unrecognized JEDEC id bytes: %02x, %02x, %02x\n",
                id[0], id[1], id[2]);
        return ERR_PTR(-ENODEV);
 }
@@ -1036,6 +1036,8 @@ static int macronix_quad_enable(struct spi_nor *nor)
        int ret, val;
 
        val = read_sr(nor);
+       if (val < 0)
+               return val;
        write_enable(nor);
 
        write_sr(nor, val | SR_QUAD_EN_MX);