Commit 4b374536 authored by Tudor Ambarus's avatar Tudor Ambarus

mtd: spi-nor: Fix retlen handling in sst_write()

In case the write of the first byte failed, retlen was incorrectly
incremented to *retlen += actual; on the exit path. retlen should be
incremented when actual data was written to the flash.
Signed-off-by: default avatarTudor Ambarus <tudor.ambarus@microchip.com>
Reviewed-by: default avatarBoris Brezillon <boris.brezillon@collabora.com>
parent 70d2c6dc
...@@ -2584,7 +2584,7 @@ static int sst_write(struct mtd_info *mtd, loff_t to, size_t len, ...@@ -2584,7 +2584,7 @@ static int sst_write(struct mtd_info *mtd, loff_t to, size_t len,
size_t *retlen, const u_char *buf) size_t *retlen, const u_char *buf)
{ {
struct spi_nor *nor = mtd_to_spi_nor(mtd); struct spi_nor *nor = mtd_to_spi_nor(mtd);
size_t actual; size_t actual = 0;
int ret; int ret;
dev_dbg(nor->dev, "to 0x%08x, len %zd\n", (u32)to, len); dev_dbg(nor->dev, "to 0x%08x, len %zd\n", (u32)to, len);
...@@ -2597,9 +2597,8 @@ static int sst_write(struct mtd_info *mtd, loff_t to, size_t len, ...@@ -2597,9 +2597,8 @@ static int sst_write(struct mtd_info *mtd, loff_t to, size_t len,
nor->sst_write_second = false; nor->sst_write_second = false;
actual = to % 2;
/* Start write from odd address. */ /* Start write from odd address. */
if (actual) { if (to % 2) {
nor->program_opcode = SPINOR_OP_BP; nor->program_opcode = SPINOR_OP_BP;
/* write one byte. */ /* write one byte. */
...@@ -2610,8 +2609,10 @@ static int sst_write(struct mtd_info *mtd, loff_t to, size_t len, ...@@ -2610,8 +2609,10 @@ static int sst_write(struct mtd_info *mtd, loff_t to, size_t len,
ret = spi_nor_wait_till_ready(nor); ret = spi_nor_wait_till_ready(nor);
if (ret) if (ret)
goto sst_write_err; goto sst_write_err;
to++;
actual++;
} }
to += actual;
/* Write out most of the data here. */ /* Write out most of the data here. */
for (; actual < len - 1; actual += 2) { for (; actual < len - 1; actual += 2) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment