Skip to content

Commit

Permalink
mtd: spi-nor: core: Check written SR value in spi_nor_write_16bit_sr_…
Browse files Browse the repository at this point in the history
…and_check()

Read back Status Register 1 to ensure that the written byte match the
received value and return -EIO if read back test failed.

Without this patch, spi_nor_write_16bit_sr_and_check() only check the
second half of the 16bit. It causes errors like spi_nor_sr_unlock()
return success incorrectly when spi_nor_write_16bit_sr_and_check()
doesn't write SR successfully.

Fixes: 39d1e33 ("mtd: spi-nor: Fix clearing of QE bit on lock()/unlock()")
Signed-off-by: Chen-Tsung Hsieh <chentsung@chromium.org>
Signed-off-by: Pratyush Yadav <p.yadav@ti.com>
Reviewed-by: Michael Walle <michael@walle.cc>
Acked-by: Pratyush Yadav <p.yadav@ti.com>
Link: https://lore.kernel.org/r/20220126073227.3401275-1-chentsung@chromium.org
  • Loading branch information
Chen-Tsung Hsieh authored and Pratyush Yadav committed Apr 21, 2022
1 parent ce522ba commit b45bbff
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions drivers/mtd/spi-nor/core.c
Expand Up @@ -788,6 +788,15 @@ static int spi_nor_write_16bit_sr_and_check(struct spi_nor *nor, u8 sr1)
if (ret)
return ret;

ret = spi_nor_read_sr(nor, sr_cr);
if (ret)
return ret;

if (sr1 != sr_cr[0]) {
dev_dbg(nor->dev, "SR: Read back test failed\n");
return -EIO;
}

if (nor->flags & SNOR_F_NO_READ_CR)
return 0;

Expand Down

0 comments on commit b45bbff

Please sign in to comment.