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
7 Content-Type: text/plain; charset=UTF-8
8 Content-Transfer-Encoding: 8bit
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
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
19 drivers/mtd/mtdcore.c | 16 +++++++---------
20 1 file changed, 7 insertions(+), 9 deletions(-)
22 --- a/drivers/mtd/mtdcore.c
23 +++ b/drivers/mtd/mtdcore.c
24 @@ -569,18 +569,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;
31 /* Check if MTD already has a device node */
32 - if (dev_of_node(&mtd->dev))
33 + if (mtd_get_of_node(mtd))
36 /* Check if a partitions node exist */
37 if (!mtd_is_partition(mtd))
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));
45 @@ -593,15 +591,15 @@ static void mtd_check_of_node(struct mtd
47 /* Search if a partition is defined with the same name */
48 for_each_child_of_node(partitions, mtd_dn) {
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))
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)) {
62 + pname = mtd_dn->name;