generic: mtd: backport SPI_NOR_HAS_LOCK
[openwrt/openwrt.git] / target / linux / layerscape / patches-4.4 / 1085-mtd-spi-nor-Check-the-return-value-from-read_sr.patch
1 From d05c68e35f42a46b352d2a4bdaef9954c946e20a Mon Sep 17 00:00:00 2001
2 From: Fabio Estevam <fabio.estevam@freescale.com>
3 Date: Fri, 20 Nov 2015 16:26:11 -0200
4 Subject: [PATCH 085/113] mtd: spi-nor: Check the return value from read_sr()
5
6 [context adjustment]
7
8 We should better check the return value from read_sr() and
9 propagate it in the case of error.
10
11 Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>
12 Signed-off-by: Brian Norris <computersforpeace@gmail.com>
13 Integrated-by: Jiang Yutang <yutang.jiang@nxp.com>
14 ---
15 drivers/mtd/spi-nor/spi-nor.c | 10 ++++++++--
16 1 file changed, 8 insertions(+), 2 deletions(-)
17
18 --- a/drivers/mtd/spi-nor/spi-nor.c
19 +++ b/drivers/mtd/spi-nor/spi-nor.c
20 @@ -479,11 +479,13 @@ static int stm_is_locked_sr(struct spi_n
21 static int stm_lock(struct spi_nor *nor, loff_t ofs, uint64_t len)
22 {
23 struct mtd_info *mtd = &nor->mtd;
24 - u8 status_old, status_new;
25 + int status_old, status_new;
26 u8 mask = SR_BP2 | SR_BP1 | SR_BP0;
27 u8 shift = ffs(mask) - 1, pow, val;
28
29 status_old = read_sr(nor);
30 + if (status_old < 0)
31 + return status_old;
32
33 /* SPI NOR always locks to the end */
34 if (ofs + len != mtd->size) {
35 @@ -529,11 +531,13 @@ static int stm_lock(struct spi_nor *nor,
36 static int stm_unlock(struct spi_nor *nor, loff_t ofs, uint64_t len)
37 {
38 struct mtd_info *mtd = &nor->mtd;
39 - uint8_t status_old, status_new;
40 + int status_old, status_new;
41 u8 mask = SR_BP2 | SR_BP1 | SR_BP0;
42 u8 shift = ffs(mask) - 1, pow, val;
43
44 status_old = read_sr(nor);
45 + if (status_old < 0)
46 + return status_old;
47
48 /* Cannot unlock; would unlock larger region than requested */
49 if (stm_is_locked_sr(nor, ofs - mtd->erasesize, mtd->erasesize,
50 @@ -1038,6 +1042,8 @@ static int macronix_quad_enable(struct s
51 int ret, val;
52
53 val = read_sr(nor);
54 + if (val < 0)
55 + return val;
56 write_enable(nor);
57
58 write_sr(nor, val | SR_QUAD_EN_MX);