gpio-nct5104d: fix compilation with kernel 6.6
[openwrt/openwrt.git] / target / linux / generic / backport-6.1 / 892-v6.5-mtd-spinand-winbond-Fix-ecc_get_status.patch
1 From f5a05060670a4d8d6523afc7963eb559c2e3615f Mon Sep 17 00:00:00 2001
2 From: Olivier Maignial <olivier.maignial@hotmail.fr>
3 Date: Fri, 23 Jun 2023 17:33:37 +0200
4 Subject: [PATCH] mtd: spinand: winbond: Fix ecc_get_status
5
6 Reading ECC status is failing.
7
8 w25n02kv_ecc_get_status() is using on-stack buffer for
9 SPINAND_GET_FEATURE_OP() output. It is not suitable for
10 DMA needs of spi-mem.
11
12 Fix this by using the spi-mem operations dedicated buffer
13 spinand->scratchbuf.
14
15 See
16 spinand->scratchbuf:
17 https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/linux/mtd/spinand.h?h=v6.3#n418
18 spi_mem_check_op():
19 https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/spi/spi-mem.c?h=v6.3#n199
20
21 Fixes: 6154c7a58348 ("mtd: spinand: winbond: add Winbond W25N02KV flash support")
22 Cc: stable@vger.kernel.org
23 Signed-off-by: Olivier Maignial <olivier.maignial@hotmail.fr>
24 Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
25 Link: https://lore.kernel.org/linux-mtd/DB4P250MB1032EDB9E36B764A33769039FE23A@DB4P250MB1032.EURP250.PROD.OUTLOOK.COM
26 ---
27 drivers/mtd/nand/spi/winbond.c | 4 ++--
28 1 file changed, 2 insertions(+), 2 deletions(-)
29
30 --- a/drivers/mtd/nand/spi/winbond.c
31 +++ b/drivers/mtd/nand/spi/winbond.c
32 @@ -108,7 +108,7 @@ static int w25n02kv_ecc_get_status(struc
33 {
34 struct nand_device *nand = spinand_to_nand(spinand);
35 u8 mbf = 0;
36 - struct spi_mem_op op = SPINAND_GET_FEATURE_OP(0x30, &mbf);
37 + struct spi_mem_op op = SPINAND_GET_FEATURE_OP(0x30, spinand->scratchbuf);
38
39 switch (status & STATUS_ECC_MASK) {
40 case STATUS_ECC_NO_BITFLIPS:
41 @@ -126,7 +126,7 @@ static int w25n02kv_ecc_get_status(struc
42 if (spi_mem_exec_op(spinand->spimem, &op))
43 return nanddev_get_ecc_conf(nand)->strength;
44
45 - mbf >>= 4;
46 + mbf = *(spinand->scratchbuf) >> 4;
47
48 if (WARN_ON(mbf > nanddev_get_ecc_conf(nand)->strength || !mbf))
49 return nanddev_get_ecc_conf(nand)->strength;