fb89b7707217fdba2f2548d0690cb0fdbba5f3ea
[openwrt/staging/jogo.git] /
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
5 in read/write
6
7 Add checking of SPI transfer errors and return them from read/write
8 functions. Also return the amount of data transferred.
9
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>
14 ---
15 drivers/mtd/devices/m25p80.c | 29 +++++++++++++++++++++--------
16 1 file changed, 21 insertions(+), 8 deletions(-)
17
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] = {};
22 struct spi_message m;
23 int cmd_sz = m25p_cmdsz(nor);
24 + ssize_t ret;
25
26 spi_message_init(&m);
27
28 @@ -98,10 +99,15 @@ static ssize_t m25p80_write(struct spi_n
29 t[1].len = len;
30 spi_message_add_tail(&t[1], &m);
31
32 - spi_sync(spi, &m);
33 + ret = spi_sync(spi, &m);
34 + if (ret)
35 + return ret;
36
37 - *retlen += m.actual_length - cmd_sz;
38 - return 0;
39 + ret = m.actual_length - cmd_sz;
40 + if (ret < 0)
41 + return -EIO;
42 + *retlen += ret;
43 + return ret;
44 }
45
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];
49 struct spi_message m;
50 unsigned int dummy = nor->read_dummy;
51 + ssize_t ret;
52
53 /* convert the dummy cycles to the number of bytes */
54 dummy /= 8;
55
56 if (spi_flash_read_supported(spi)) {
57 struct spi_flash_read_message msg;
58 - int ret;
59
60 memset(&msg, 0, sizeof(msg));
61
62 @@ -151,7 +157,9 @@ static ssize_t m25p80_read(struct spi_no
63
64 ret = spi_flash_read(spi, &msg);
65 *retlen = msg.retlen;
66 - return ret;
67 + if (ret < 0)
68 + return ret;
69 + return msg.retlen;
70 }
71
72 spi_message_init(&m);
73 @@ -169,10 +177,15 @@ static ssize_t m25p80_read(struct spi_no
74 t[1].len = len;
75 spi_message_add_tail(&t[1], &m);
76
77 - spi_sync(spi, &m);
78 + ret = spi_sync(spi, &m);
79 + if (ret)
80 + return ret;
81
82 - *retlen = m.actual_length - m25p_cmdsz(nor) - dummy;
83 - return 0;
84 + ret = m.actual_length - m25p_cmdsz(nor) - dummy;
85 + if (ret < 0)
86 + return -EIO;
87 + *retlen += ret;
88 + return ret;
89 }
90
91 static int m25p80_erase(struct spi_nor *nor, loff_t offset)