kernel: backport fixes for realtek r8152
[openwrt/openwrt.git] / target / linux / generic / backport-5.15 / 409-v6.3-mtd-mtdpart-Don-t-create-platform-device-that-ll-nev.patch
1 From fb42378dcc7f247df56f0ecddfdae85487495fbc Mon Sep 17 00:00:00 2001
2 From: Saravana Kannan <saravanak@google.com>
3 Date: Mon, 6 Feb 2023 17:42:04 -0800
4 Subject: [PATCH] mtd: mtdpart: Don't create platform device that'll never
5 probe
6
7 These "nvmem-cells" platform devices never get probed because there's no
8 platform driver for it and it's never used anywhere else. So it's a
9 waste of memory. These devices also cause fw_devlink to block nvmem
10 consumers of "nvmem-cells" partition from probing because the supplier
11 device never probes.
12
13 So stop creating platform devices for nvmem-cells partitions to avoid
14 wasting memory and to avoid blocking probing of consumers.
15
16 Reported-by: Maxim Kiselev <bigunclemax@gmail.com>
17 Fixes: bcdf0315a61a ("mtd: call of_platform_populate() for MTD partitions")
18 Signed-off-by: Saravana Kannan <saravanak@google.com>
19 Tested-by: Maksim Kiselev <bigunclemax@gmail.com>
20 Tested-by: Douglas Anderson <dianders@chromium.org>
21 Tested-by: Geert Uytterhoeven <geert+renesas@glider.be>
22 Tested-by: Luca Weiss <luca.weiss@fairphone.com> # qcom/sm7225-fairphone-fp4
23 Link: https://lore.kernel.org/r/20230207014207.1678715-13-saravanak@google.com
24 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
25 ---
26 drivers/mtd/mtdpart.c | 10 ++++++++++
27 1 file changed, 10 insertions(+)
28
29 --- a/drivers/mtd/mtdpart.c
30 +++ b/drivers/mtd/mtdpart.c
31 @@ -577,6 +577,7 @@ static int mtd_part_of_parse(struct mtd_
32 {
33 struct mtd_part_parser *parser;
34 struct device_node *np;
35 + struct device_node *child;
36 struct property *prop;
37 struct device *dev;
38 const char *compat;
39 @@ -594,6 +595,15 @@ static int mtd_part_of_parse(struct mtd_
40 else
41 np = of_get_child_by_name(np, "partitions");
42
43 + /*
44 + * Don't create devices that are added to a bus but will never get
45 + * probed. That'll cause fw_devlink to block probing of consumers of
46 + * this partition until the partition device is probed.
47 + */
48 + for_each_child_of_node(np, child)
49 + if (of_device_is_compatible(child, "nvmem-cells"))
50 + of_node_set_flag(child, OF_POPULATED);
51 +
52 of_property_for_each_string(np, "compatible", prop, compat) {
53 parser = mtd_part_get_compatible_parser(compat);
54 if (!parser)