kernel: fix mtd/NVMEM regression affecting U-Boot env NVMEM driver
[openwrt/staging/stintel.git] / target / linux / generic / pending-6.1 / 401-mtd-don-t-register-NVMEM-devices-for-partitions-with.patch
1 From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <rafal@milecki.pl>
2 Date: Tue, 31 Oct 2023 15:51:01 +0100
3 Subject: [PATCH] mtd: don't register NVMEM devices for partitions with custom
4 drivers
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8
9 This fixes issue exposed by upstream commit f4cf4e5db331 ("Revert
10 "nvmem: add new config option"").
11
12 Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
13 ---
14 drivers/mtd/mtdcore.c | 23 +++++++++++++++++++++++
15 1 file changed, 23 insertions(+)
16
17 --- a/drivers/mtd/mtdcore.c
18 +++ b/drivers/mtd/mtdcore.c
19 @@ -519,6 +519,29 @@ static int mtd_nvmem_add(struct mtd_info
20 struct device_node *node = mtd_get_of_node(mtd);
21 struct nvmem_config config = {};
22
23 + /*
24 + * Do NOT register NVMEM device for any partition that is meant to be
25 + * handled by a U-Boot env driver. That would result in associating two
26 + * different NVMEM devices with the same OF node.
27 + *
28 + * An example of unwanted behaviour of above (forwardtrace):
29 + * of_get_mac_addr_nvmem()
30 + * of_nvmem_cell_get()
31 + * __nvmem_device_get()
32 + *
33 + * We can't have __nvmem_device_get() return "mtdX" NVMEM device instead
34 + * of U-Boot env NVMEM device. That would result in failing to find
35 + * NVMEM cell.
36 + *
37 + * This issue seems to affect U-Boot env case only and will go away with
38 + * switch to NVMEM layouts.
39 + */
40 + if (of_device_is_compatible(node, "u-boot,env") ||
41 + of_device_is_compatible(node, "u-boot,env-redundant-bool") ||
42 + of_device_is_compatible(node, "u-boot,env-redundant-count") ||
43 + of_device_is_compatible(node, "brcm,env"))
44 + return 0;
45 +
46 config.id = -1;
47 config.dev = &mtd->dev;
48 config.name = dev_name(&mtd->dev);