Commit 0bad7b93 authored by Michal Suchanek's avatar Michal Suchanek Committed by Brian Norris

mtd: spi-nor: check return value from write

SPI NOR hardware drivers now return useful value from their write
functions so check them.
Signed-off-by: default avatarMichal Suchanek <hramrach@gmail.com>
Signed-off-by: default avatarBrian Norris <computersforpeace@gmail.com>
Tested-by Cyrille Pitchen <cyrille.pitchen@atmel.com>
Acked-by: default avatarMichal Suchanek <hramrach@gmail.com>
Tested-by: default avatarMichal Suchanek <hramrach@gmail.com>
parent bc418cd2
...@@ -1063,10 +1063,14 @@ static int sst_write(struct mtd_info *mtd, loff_t to, size_t len, ...@@ -1063,10 +1063,14 @@ static int sst_write(struct mtd_info *mtd, loff_t to, size_t len,
nor->program_opcode = SPINOR_OP_BP; nor->program_opcode = SPINOR_OP_BP;
/* write one byte. */ /* write one byte. */
nor->write(nor, to, 1, retlen, buf); ret = nor->write(nor, to, 1, retlen, buf);
if (ret < 0)
goto sst_write_err;
WARN(ret != 1, "While writing 1 byte written %i bytes\n",
(int)ret);
ret = spi_nor_wait_till_ready(nor); ret = spi_nor_wait_till_ready(nor);
if (ret) if (ret)
goto time_out; goto sst_write_err;
} }
to += actual; to += actual;
...@@ -1075,10 +1079,14 @@ static int sst_write(struct mtd_info *mtd, loff_t to, size_t len, ...@@ -1075,10 +1079,14 @@ static int sst_write(struct mtd_info *mtd, loff_t to, size_t len,
nor->program_opcode = SPINOR_OP_AAI_WP; nor->program_opcode = SPINOR_OP_AAI_WP;
/* write two bytes. */ /* write two bytes. */
nor->write(nor, to, 2, retlen, buf + actual); ret = nor->write(nor, to, 2, retlen, buf + actual);
if (ret < 0)
goto sst_write_err;
WARN(ret != 2, "While writing 2 bytes written %i bytes\n",
(int)ret);
ret = spi_nor_wait_till_ready(nor); ret = spi_nor_wait_till_ready(nor);
if (ret) if (ret)
goto time_out; goto sst_write_err;
to += 2; to += 2;
nor->sst_write_second = true; nor->sst_write_second = true;
} }
...@@ -1087,21 +1095,24 @@ static int sst_write(struct mtd_info *mtd, loff_t to, size_t len, ...@@ -1087,21 +1095,24 @@ static int sst_write(struct mtd_info *mtd, loff_t to, size_t len,
write_disable(nor); write_disable(nor);
ret = spi_nor_wait_till_ready(nor); ret = spi_nor_wait_till_ready(nor);
if (ret) if (ret)
goto time_out; goto sst_write_err;
/* Write out trailing byte if it exists. */ /* Write out trailing byte if it exists. */
if (actual != len) { if (actual != len) {
write_enable(nor); write_enable(nor);
nor->program_opcode = SPINOR_OP_BP; nor->program_opcode = SPINOR_OP_BP;
nor->write(nor, to, 1, retlen, buf + actual); ret = nor->write(nor, to, 1, retlen, buf + actual);
if (ret < 0)
goto sst_write_err;
WARN(ret != 1, "While writing 1 byte written %i bytes\n",
(int)ret);
ret = spi_nor_wait_till_ready(nor); ret = spi_nor_wait_till_ready(nor);
if (ret) if (ret)
goto time_out; goto sst_write_err;
write_disable(nor); write_disable(nor);
} }
time_out: sst_write_err:
spi_nor_unlock_and_unprep(nor, SPI_NOR_OPS_WRITE); spi_nor_unlock_and_unprep(nor, SPI_NOR_OPS_WRITE);
return ret; return ret;
} }
...@@ -1130,14 +1141,18 @@ static int spi_nor_write(struct mtd_info *mtd, loff_t to, size_t len, ...@@ -1130,14 +1141,18 @@ static int spi_nor_write(struct mtd_info *mtd, loff_t to, size_t len,
/* do all the bytes fit onto one page? */ /* do all the bytes fit onto one page? */
if (page_offset + len <= nor->page_size) { if (page_offset + len <= nor->page_size) {
nor->write(nor, to, len, retlen, buf); ret = nor->write(nor, to, len, retlen, buf);
if (ret < 0)
goto write_err;
} else { } else {
/* the size of data remaining on the first page */ /* the size of data remaining on the first page */
page_size = nor->page_size - page_offset; page_size = nor->page_size - page_offset;
nor->write(nor, to, page_size, retlen, buf); ret = nor->write(nor, to, page_size, retlen, buf);
if (ret < 0)
goto write_err;
/* write everything in nor->page_size chunks */ /* write everything in nor->page_size chunks */
for (i = page_size; i < len; i += page_size) { for (i = ret; i < len; ) {
page_size = len - i; page_size = len - i;
if (page_size > nor->page_size) if (page_size > nor->page_size)
page_size = nor->page_size; page_size = nor->page_size;
...@@ -1148,7 +1163,11 @@ static int spi_nor_write(struct mtd_info *mtd, loff_t to, size_t len, ...@@ -1148,7 +1163,11 @@ static int spi_nor_write(struct mtd_info *mtd, loff_t to, size_t len,
write_enable(nor); write_enable(nor);
nor->write(nor, to + i, page_size, retlen, buf + i); ret = nor->write(nor, to + i, page_size, retlen,
buf + i);
if (ret < 0)
goto write_err;
i += ret;
} }
} }
......
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