eb6be5ed00e2f0928f924b396885beba80a685d5
[openwrt/staging/pepe2k.git] /
1 From 63db0cb35e1cb3b3c134906d1062f65513fdda2d Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <rafal@milecki.pl>
3 Date: Tue, 4 Oct 2022 10:37:09 +0200
4 Subject: [PATCH] mtd: core: simplify (a bit) code find partition-matching
5 dynamic OF node
6 MIME-Version: 1.0
7 Content-Type: text/plain; charset=UTF-8
8 Content-Transfer-Encoding: 8bit
9
10 1. Don't hardcode "partition-" string twice
11 2. Use simpler logic & use ->name to avoid of_property_read_string()
12 3. Use mtd_get_of_node() helper
13
14 Cc: Christian Marangi <ansuelsmth@gmail.com>
15 Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
16 Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
17 Link: https://lore.kernel.org/linux-mtd/20221004083710.27704-1-zajec5@gmail.com
18 ---
19 drivers/mtd/mtdcore.c | 16 +++++++---------
20 1 file changed, 7 insertions(+), 9 deletions(-)
21
22 --- a/drivers/mtd/mtdcore.c
23 +++ b/drivers/mtd/mtdcore.c
24 @@ -551,18 +551,16 @@ static void mtd_check_of_node(struct mtd
25 struct device_node *partitions, *parent_dn, *mtd_dn = NULL;
26 const char *pname, *prefix = "partition-";
27 int plen, mtd_name_len, offset, prefix_len;
28 - struct mtd_info *parent;
29 bool found = false;
30
31 /* Check if MTD already has a device node */
32 - if (dev_of_node(&mtd->dev))
33 + if (mtd_get_of_node(mtd))
34 return;
35
36 /* Check if a partitions node exist */
37 if (!mtd_is_partition(mtd))
38 return;
39 - parent = mtd->parent;
40 - parent_dn = of_node_get(dev_of_node(&parent->dev));
41 + parent_dn = of_node_get(mtd_get_of_node(mtd->parent));
42 if (!parent_dn)
43 return;
44
45 @@ -575,15 +573,15 @@ static void mtd_check_of_node(struct mtd
46
47 /* Search if a partition is defined with the same name */
48 for_each_child_of_node(partitions, mtd_dn) {
49 - offset = 0;
50 -
51 /* Skip partition with no/wrong prefix */
52 - if (!of_node_name_prefix(mtd_dn, "partition-"))
53 + if (!of_node_name_prefix(mtd_dn, prefix))
54 continue;
55
56 /* Label have priority. Check that first */
57 - if (of_property_read_string(mtd_dn, "label", &pname)) {
58 - of_property_read_string(mtd_dn, "name", &pname);
59 + if (!of_property_read_string(mtd_dn, "label", &pname)) {
60 + offset = 0;
61 + } else {
62 + pname = mtd_dn->name;
63 offset = prefix_len;
64 }
65