Skip to contentSkip to conversation

mtd: core: simplify (a bit) code find partition-matching dynamic OF node

PATCH Superseded Rafał Miłecki 1 participant 3 messages Jul 7, 2022 – Jul 11, 2022 Memory technology devices (MTD)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 mtd: core: simplify (a bit) code find partition-matching dynamic OF node

From: Rafał Miłecki <[email protected]>

1. Don't hardcode "partition-" string twice
2. Use simpler logic & use ->name to avoid of_property_read_string()

---
 drivers/mtd/mtdcore.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/mtd/mtdcore.c +5 -5
index dc9b33990895..79c447fe30b4 100644
@@ -573,15 +573,15 @@ static void mtd_check_of_node(struct mtd_info *mtd)
 
 	/* Search if a partition is defined with the same name */
 	for_each_child_of_node(partitions, mtd_dn) {
-		offset = 0;
-
 		/* Skip partition with no/wrong prefix */
-		if (!of_node_name_prefix(mtd_dn, "partition-"))
+		if (!of_node_name_prefix(mtd_dn, prefix))
 			continue;
 
 		/* Label have priority. Check that first */
-		if (of_property_read_string(mtd_dn, "label", &pname)) {
-			of_property_read_string(mtd_dn, "name", &pname);
+		if (!of_property_read_string(mtd_dn, "label", &pname)) {
+			offset = 0;
+		} else {
+			pname = mtd_dn->name;
 			offset = prefix_len;
 		}
 
Signature · 1 line
2.34.1
#1 lore raw

PATCH 2/2 mtd: core: find OF node for every MTD partition

From: Rafał Miłecki <[email protected]>

Don't limit this feature to the "nvmem-cells". There are more cases to this.
1. Dynamic partitions may need to be handled with parsers This applies to "fixed-partitions" parser and all custom ones.
2. Dynamic partitions can be handled with specific drivers Consider "u-boot,env" as specified in the u-boot,env.yaml.

---
 drivers/mtd/mtdcore.c | 11 +----------
 1 file changed, 1 insertion(+), 10 deletions(-)
drivers/mtd/mtdcore.c +1 -10
index 79c447fe30b4..f7693736dde4 100644
@@ -552,7 +552,6 @@ static void mtd_check_of_node(struct mtd_info *mtd)
 	const char *pname, *prefix = "partition-";
 	int plen, mtd_name_len, offset, prefix_len;
 	struct mtd_info *parent;
-	bool found = false;
 
 	/* Check if MTD already has a device node */
 	if (dev_of_node(&mtd->dev))
@@ -588,19 +587,11 @@ static void mtd_check_of_node(struct mtd_info *mtd)
 		plen = strlen(pname) - offset;
 		if (plen == mtd_name_len &&
 		    !strncmp(mtd->name, pname + offset, plen)) {
-			found = true;
+			mtd_set_of_node(mtd, mtd_dn);
 			break;
 		}
 	}
 
-	if (!found)
-		goto exit_partitions;
-
-	/* Set of_node only for nvmem */
-	if (of_device_is_compatible(mtd_dn, "nvmem-cells"))
-		mtd_set_of_node(mtd, mtd_dn);
-
-exit_partitions:
 	of_node_put(partitions);
 exit_parent:
 	of_node_put(parent_dn);
Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH 2/2] mtd: core: find OF node for every MTD partition

Quoted 10 lines · Rafał Miłecki

From: Rafał Miłecki <[email protected]>

Don't limit this feature to the "nvmem-cells". There are more cases to this.
1. Dynamic partitions may need to be handled with parsers This applies to "fixed-partitions" parser and all custom ones.
2. Dynamic partitions can be handled with specific drivers Consider "u-boot,env" as specified in the u-boot,env.yaml.

This code needs more work, please drop this patchset for now.

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/