brcm63xx: remove misleading warning about partial SPI NOR writes
[openwrt/openwrt.git] / target / linux / brcm63xx / patches-4.4 / 000-4.8-06-mtd-spi-nor-check-return-value-from-write.patch
1 From 0bad7b9304d543dd7627f4cd564aea5d7338b950 Mon Sep 17 00:00:00 2001
2 From: Michal Suchanek <hramrach@gmail.com>
3 Date: Thu, 5 May 2016 17:31:52 -0700
4 Subject: [PATCH 06/10] mtd: spi-nor: check return value from write
5
6 SPI NOR hardware drivers now return useful value from their write
7 functions so check them.
8
9 Signed-off-by: Michal Suchanek <hramrach@gmail.com>
10 Signed-off-by: Brian Norris <computersforpeace@gmail.com>
11 Tested-by Cyrille Pitchen <cyrille.pitchen@atmel.com>
12 Acked-by: Michal Suchanek <hramrach@gmail.com>
13 Tested-by: Michal Suchanek <hramrach@gmail.com>
14 ---
15 drivers/mtd/spi-nor/spi-nor.c | 45 ++++++++++++++++++++++++++++++-------------
16 1 file changed, 32 insertions(+), 13 deletions(-)
17
18 --- a/drivers/mtd/spi-nor/spi-nor.c
19 +++ b/drivers/mtd/spi-nor/spi-nor.c
20 @@ -922,10 +922,14 @@ static int sst_write(struct mtd_info *mt
21 nor->program_opcode = SPINOR_OP_BP;
22
23 /* write one byte. */
24 - nor->write(nor, to, 1, retlen, buf);
25 + ret = nor->write(nor, to, 1, retlen, buf);
26 + if (ret < 0)
27 + goto sst_write_err;
28 + WARN(ret != 1, "While writing 1 byte written %i bytes\n",
29 + (int)ret);
30 ret = spi_nor_wait_till_ready(nor);
31 if (ret)
32 - goto time_out;
33 + goto sst_write_err;
34 }
35 to += actual;
36
37 @@ -934,10 +938,14 @@ static int sst_write(struct mtd_info *mt
38 nor->program_opcode = SPINOR_OP_AAI_WP;
39
40 /* write two bytes. */
41 - nor->write(nor, to, 2, retlen, buf + actual);
42 + ret = nor->write(nor, to, 2, retlen, buf + actual);
43 + if (ret < 0)
44 + goto sst_write_err;
45 + WARN(ret != 2, "While writing 2 bytes written %i bytes\n",
46 + (int)ret);
47 ret = spi_nor_wait_till_ready(nor);
48 if (ret)
49 - goto time_out;
50 + goto sst_write_err;
51 to += 2;
52 nor->sst_write_second = true;
53 }
54 @@ -946,21 +954,24 @@ static int sst_write(struct mtd_info *mt
55 write_disable(nor);
56 ret = spi_nor_wait_till_ready(nor);
57 if (ret)
58 - goto time_out;
59 + goto sst_write_err;
60
61 /* Write out trailing byte if it exists. */
62 if (actual != len) {
63 write_enable(nor);
64
65 nor->program_opcode = SPINOR_OP_BP;
66 - nor->write(nor, to, 1, retlen, buf + actual);
67 -
68 + ret = nor->write(nor, to, 1, retlen, buf + actual);
69 + if (ret < 0)
70 + goto sst_write_err;
71 + WARN(ret != 1, "While writing 1 byte written %i bytes\n",
72 + (int)ret);
73 ret = spi_nor_wait_till_ready(nor);
74 if (ret)
75 - goto time_out;
76 + goto sst_write_err;
77 write_disable(nor);
78 }
79 -time_out:
80 +sst_write_err:
81 spi_nor_unlock_and_unprep(nor, SPI_NOR_OPS_WRITE);
82 return ret;
83 }
84 @@ -989,14 +1000,18 @@ static int spi_nor_write(struct mtd_info
85
86 /* do all the bytes fit onto one page? */
87 if (page_offset + len <= nor->page_size) {
88 - nor->write(nor, to, len, retlen, buf);
89 + ret = nor->write(nor, to, len, retlen, buf);
90 + if (ret < 0)
91 + goto write_err;
92 } else {
93 /* the size of data remaining on the first page */
94 page_size = nor->page_size - page_offset;
95 - nor->write(nor, to, page_size, retlen, buf);
96 + ret = nor->write(nor, to, page_size, retlen, buf);
97 + if (ret < 0)
98 + goto write_err;
99
100 /* write everything in nor->page_size chunks */
101 - for (i = page_size; i < len; i += page_size) {
102 + for (i = ret; i < len; ) {
103 page_size = len - i;
104 if (page_size > nor->page_size)
105 page_size = nor->page_size;
106 @@ -1007,7 +1022,11 @@ static int spi_nor_write(struct mtd_info
107
108 write_enable(nor);
109
110 - nor->write(nor, to + i, page_size, retlen, buf + i);
111 + ret = nor->write(nor, to + i, page_size, retlen,
112 + buf + i);
113 + if (ret < 0)
114 + goto write_err;
115 + i += ret;
116 }
117 }
118