1 From 1992297b0810a42d78ec7b4de15304eb0489fd97 Mon Sep 17 00:00:00 2001
2 From: Michal Suchanek <hramrach@gmail.com>
3 Date: Thu, 5 May 2016 17:31:48 -0700
4 Subject: [PATCH 02/10] mtd: m25p80: return amount of data transferred or error
7 Add checking of SPI transfer errors and return them from read/write
8 functions. Also return the amount of data transferred.
10 Signed-off-by: Michal Suchanek <hramrach@gmail.com>
11 Signed-off-by: Brian Norris <computersforpeace@gmail.com>
12 Acked-by: Michal Suchanek <hramrach@gmail.com>
13 Tested-by: Michal Suchanek <hramrach@gmail.com>
15 drivers/mtd/devices/m25p80.c | 29 +++++++++++++++++++++--------
16 1 file changed, 21 insertions(+), 8 deletions(-)
18 --- a/drivers/mtd/devices/m25p80.c
19 +++ b/drivers/mtd/devices/m25p80.c
20 @@ -81,6 +81,7 @@ static ssize_t m25p80_write(struct spi_n
21 struct spi_transfer t[2] = {};
23 int cmd_sz = m25p_cmdsz(nor);
28 @@ -98,10 +99,15 @@ static ssize_t m25p80_write(struct spi_n
30 spi_message_add_tail(&t[1], &m);
33 + ret = spi_sync(spi, &m);
37 - *retlen += m.actual_length - cmd_sz;
39 + ret = m.actual_length - cmd_sz;
46 static inline unsigned int m25p80_rx_nbits(struct spi_nor *nor)
47 @@ -128,13 +134,13 @@ static ssize_t m25p80_read(struct spi_no
48 struct spi_transfer t[2];
50 unsigned int dummy = nor->read_dummy;
53 /* convert the dummy cycles to the number of bytes */
56 if (spi_flash_read_supported(spi)) {
57 struct spi_flash_read_message msg;
60 memset(&msg, 0, sizeof(msg));
62 @@ -151,7 +157,9 @@ static ssize_t m25p80_read(struct spi_no
64 ret = spi_flash_read(spi, &msg);
73 @@ -169,10 +177,15 @@ static ssize_t m25p80_read(struct spi_no
75 spi_message_add_tail(&t[1], &m);
78 + ret = spi_sync(spi, &m);
82 - *retlen = m.actual_length - m25p_cmdsz(nor) - dummy;
84 + ret = m.actual_length - m25p_cmdsz(nor) - dummy;
91 static int m25p80_erase(struct spi_nor *nor, loff_t offset)