generic: mtd: backport SPI_NOR_HAS_LOCK
[openwrt/openwrt.git] / target / linux / layerscape / patches-4.4 / 1096-mtd-spi-nor-add-read-loop.patch
1 From b5929f91416d64afacf46c649f38cc8f0eea50d2 Mon Sep 17 00:00:00 2001
2 From: Michal Suchanek <hramrach@gmail.com>
3 Date: Wed, 2 Dec 2015 10:38:20 +0000
4 Subject: [PATCH 096/113] mtd: spi-nor: add read loop
5
6 mtdblock and ubi do not handle the situation when read returns less data
7 than requested. Loop in spi-nor until buffer is filled or an error is
8 returned.
9
10 Signed-off-by: Michal Suchanek <hramrach@gmail.com>
11 Signed-off-by: Hou Zhiqiang <Zhiqiang.Hou@freescale.com>
12 ---
13 drivers/mtd/spi-nor/spi-nor.c | 20 ++++++++++++++------
14 1 file changed, 14 insertions(+), 6 deletions(-)
15
16 --- a/drivers/mtd/spi-nor/spi-nor.c
17 +++ b/drivers/mtd/spi-nor/spi-nor.c
18 @@ -921,14 +921,22 @@ static int spi_nor_read(struct mtd_info
19 if (ret)
20 return ret;
21
22 - ret = nor->read(nor, from, len, buf);
23 + while (len) {
24 + ret = nor->read(nor, from, len, buf);
25 + if (ret <= 0)
26 + goto read_err;
27
28 - spi_nor_unlock_and_unprep(nor, SPI_NOR_OPS_READ);
29 - if (ret < 0)
30 - return ret;
31 + WARN_ON(ret > len);
32 + *retlen += ret;
33 + buf += ret;
34 + from += ret;
35 + len -= ret;
36 + }
37 + ret = 0;
38
39 - *retlen += ret;
40 - return 0;
41 +read_err:
42 + spi_nor_unlock_and_unprep(nor, SPI_NOR_OPS_READ);
43 + return ret;
44 }
45
46 static int sst_write(struct mtd_info *mtd, loff_t to, size_t len,