[PATCH v2 2/6] mtd: m25p80: Add read/write error check and return
Michal Suchanek
hramrach at gmail.com
Mon Aug 3 11:39:01 PDT 2015
Add checking of SPI transfer errors and return them from read/write
functions.
Signed-off-by: Michal Suchanek <hramrach at gmail.com>
---
drivers/mtd/devices/m25p80.c | 31 +++++++++++++++++++++----------
1 file changed, 21 insertions(+), 10 deletions(-)
diff --git a/drivers/mtd/devices/m25p80.c b/drivers/mtd/devices/m25p80.c
index d313f948b..c93bc41 100644
--- a/drivers/mtd/devices/m25p80.c
+++ b/drivers/mtd/devices/m25p80.c
@@ -75,7 +75,7 @@ static int m25p80_write_reg(struct spi_nor *nor, u8 opcode, u8 *buf, int len,
return spi_write(spi, flash->command, len + 1);
}
-static void m25p80_write(struct spi_nor *nor, loff_t to, size_t len,
+static ssize_t m25p80_write(struct spi_nor *nor, loff_t to, size_t len,
size_t *retlen, const u_char *buf)
{
struct m25p *flash = nor->priv;
@@ -83,6 +83,7 @@ static void m25p80_write(struct spi_nor *nor, loff_t to, size_t len,
struct spi_transfer t[2] = {};
struct spi_message m;
int cmd_sz = m25p_cmdsz(nor);
+ ssize_t ret;
spi_message_init(&m);
@@ -100,9 +101,15 @@ static void m25p80_write(struct spi_nor *nor, loff_t to, size_t len,
t[1].len = len;
spi_message_add_tail(&t[1], &m);
- spi_sync(spi, &m);
+ ret = spi_sync(spi, &m);
+ if (ret)
+ return ret;
- *retlen += m.actual_length - cmd_sz;
+ ret = m.actual_length - cmd_sz;
+ if (ret < 0)
+ return -EIO;
+ *retlen += ret;
+ return ret;
}
static inline unsigned int m25p80_rx_nbits(struct spi_nor *nor)
@@ -121,7 +128,7 @@ static inline unsigned int m25p80_rx_nbits(struct spi_nor *nor)
* Read an address range from the nor chip. The address range
* may be any size provided it is within the physical boundaries.
*/
-static int m25p80_read(struct spi_nor *nor, loff_t from, size_t len,
+static ssize_t m25p80_read(struct spi_nor *nor, loff_t from, size_t len,
size_t *retlen, u_char *buf)
{
struct m25p *flash = nor->priv;
@@ -129,6 +136,7 @@ static int m25p80_read(struct spi_nor *nor, loff_t from, size_t len,
struct spi_transfer t[2];
struct spi_message m;
unsigned int dummy = nor->read_dummy;
+ ssize_t ret;
/* convert the dummy cycles to the number of bytes */
dummy /= 8;
@@ -148,10 +156,15 @@ static int m25p80_read(struct spi_nor *nor, loff_t from, size_t len,
t[1].len = len;
spi_message_add_tail(&t[1], &m);
- spi_sync(spi, &m);
+ ret = spi_sync(spi, &m);
+ if (ret)
+ return ret;
- *retlen = m.actual_length - m25p_cmdsz(nor) - dummy;
- return 0;
+ ret = m.actual_length - m25p_cmdsz(nor) - dummy;
+ if (ret < 0)
+ return -EIO;
+ *retlen += ret;
+ return ret;
}
static int m25p80_erase(struct spi_nor *nor, loff_t offset)
@@ -165,9 +178,7 @@ static int m25p80_erase(struct spi_nor *nor, loff_t offset)
flash->command[0] = nor->erase_opcode;
m25p_addr2cmd(nor, offset, flash->command);
- spi_write(flash->spi, flash->command, m25p_cmdsz(nor));
-
- return 0;
+ return spi_write(flash->spi, flash->command, m25p_cmdsz(nor));
}
/*
--
2.1.4
More information about the linux-mtd
mailing list