devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] mtd: core: simplify (a bit) code find partition-matching dynamic OF node
@ 2022-07-07 16:36 Rafał Miłecki
  2022-07-07 16:36 ` [PATCH 2/2] mtd: core: find OF node for every MTD partition Rafał Miłecki
  0 siblings, 1 reply; 3+ messages in thread
From: Rafał Miłecki @ 2022-07-07 16:36 UTC (permalink / raw)
  To: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra
  Cc: ansuelsmth, linux-mtd, devicetree, linux-kernel,
	Rafał Miłecki

From: Rafał Miłecki <rafal@milecki.pl>

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

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
---
 drivers/mtd/mtdcore.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
index dc9b33990895..79c447fe30b4 100644
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
@@ -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;
 		}
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/2] mtd: core: find OF node for every MTD partition
  2022-07-07 16:36 [PATCH 1/2] mtd: core: simplify (a bit) code find partition-matching dynamic OF node Rafał Miłecki
@ 2022-07-07 16:36 ` Rafał Miłecki
  2022-07-11  9:45   ` Rafał Miłecki
  0 siblings, 1 reply; 3+ messages in thread
From: Rafał Miłecki @ 2022-07-07 16:36 UTC (permalink / raw)
  To: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra
  Cc: ansuelsmth, linux-mtd, devicetree, linux-kernel,
	Rafał Miłecki

From: Rafał Miłecki <rafal@milecki.pl>

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.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
---
 drivers/mtd/mtdcore.c | 11 +----------
 1 file changed, 1 insertion(+), 10 deletions(-)

diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
index 79c447fe30b4..f7693736dde4 100644
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
@@ -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);
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH 2/2] mtd: core: find OF node for every MTD partition
  2022-07-07 16:36 ` [PATCH 2/2] mtd: core: find OF node for every MTD partition Rafał Miłecki
@ 2022-07-11  9:45   ` Rafał Miłecki
  0 siblings, 0 replies; 3+ messages in thread
From: Rafał Miłecki @ 2022-07-11  9:45 UTC (permalink / raw)
  To: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra
  Cc: ansuelsmth, linux-mtd, devicetree, linux-kernel,
	Rafał Miłecki

On 7.07.2022 18:36, Rafał Miłecki wrote:
> From: Rafał Miłecki <rafal@milecki.pl>
> 
> 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.
> 
> Signed-off-by: Rafał Miłecki <rafal@milecki.pl>

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-07-11 10:35 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-07-07 16:36 [PATCH 1/2] mtd: core: simplify (a bit) code find partition-matching dynamic OF node Rafał Miłecki
2022-07-07 16:36 ` [PATCH 2/2] mtd: core: find OF node for every MTD partition Rafał Miłecki
2022-07-11  9:45   ` Rafał Miłecki

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).