linux-mtd.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH V2 1/2] mtd: core: simplify (a bit) code find partition-matching dynamic OF node
@ 2022-10-04  8:37 Rafał Miłecki
  2022-10-04  8:37 ` [PATCH V2 2/2] mtd: core: try to find OF node for every MTD partition Rafał Miłecki
  2022-10-18  9:56 ` [PATCH V2 1/2] mtd: core: simplify (a bit) code find partition-matching dynamic OF node Miquel Raynal
  0 siblings, 2 replies; 4+ messages in thread
From: Rafał Miłecki @ 2022-10-04  8:37 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()
3. Use mtd_get_of_node() helper

Cc: Christian Marangi <ansuelsmth@gmail.com>
Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
---
 drivers/mtd/mtdcore.c | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
index 18aa54460d36..2211e0ed6cc9 100644
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
@@ -551,18 +551,16 @@ static void mtd_check_of_node(struct mtd_info *mtd)
 	struct device_node *partitions, *parent_dn, *mtd_dn = NULL;
 	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))
+	if (mtd_get_of_node(mtd))
 		return;
 
 	/* Check if a partitions node exist */
 	if (!mtd_is_partition(mtd))
 		return;
-	parent = mtd->parent;
-	parent_dn = dev_of_node(&parent->dev);
+	parent_dn = mtd_get_of_node(mtd->parent);
 	if (!parent_dn)
 		return;
 
@@ -575,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


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

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

* [PATCH V2 2/2] mtd: core: try to find OF node for every MTD partition
  2022-10-04  8:37 [PATCH V2 1/2] mtd: core: simplify (a bit) code find partition-matching dynamic OF node Rafał Miłecki
@ 2022-10-04  8:37 ` Rafał Miłecki
  2022-10-18  9:56   ` Miquel Raynal
  2022-10-18  9:56 ` [PATCH V2 1/2] mtd: core: simplify (a bit) code find partition-matching dynamic OF node Miquel Raynal
  1 sibling, 1 reply; 4+ messages in thread
From: Rafał Miłecki @ 2022-10-04  8:37 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>

So far this feature was limited to the top-level "nvmem-cells" node.
There are multiple parsers creating partitions and subpartitions
dynamically. Extend that code to handle them too.

This allows finding partition-* node for every MTD (sub)partition.

Random example:

partitions {
	compatible = "brcm,bcm947xx-cfe-partitions";

	partition-firmware {
		compatible = "brcm,trx";

		partition-loader {
		};
	};
};

Cc: Christian Marangi <ansuelsmth@gmail.com>
Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
---
 drivers/mtd/mtdcore.c | 18 ++++++------------
 1 file changed, 6 insertions(+), 12 deletions(-)

diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
index 2211e0ed6cc9..07249af4f890 100644
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
@@ -551,20 +551,22 @@ static void mtd_check_of_node(struct mtd_info *mtd)
 	struct device_node *partitions, *parent_dn, *mtd_dn = NULL;
 	const char *pname, *prefix = "partition-";
 	int plen, mtd_name_len, offset, prefix_len;
-	bool found = false;
 
 	/* Check if MTD already has a device node */
 	if (mtd_get_of_node(mtd))
 		return;
 
-	/* Check if a partitions node exist */
 	if (!mtd_is_partition(mtd))
 		return;
+
 	parent_dn = mtd_get_of_node(mtd->parent);
 	if (!parent_dn)
 		return;
 
-	partitions = of_get_child_by_name(parent_dn, "partitions");
+	if (mtd_is_partition(mtd->parent))
+		partitions = of_node_get(parent_dn);
+	else
+		partitions = of_get_child_by_name(parent_dn, "partitions");
 	if (!partitions)
 		goto exit_parent;
 
@@ -588,19 +590,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


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

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

* Re: [PATCH V2 2/2] mtd: core: try to find OF node for every MTD partition
  2022-10-04  8:37 ` [PATCH V2 2/2] mtd: core: try to find OF node for every MTD partition Rafał Miłecki
@ 2022-10-18  9:56   ` Miquel Raynal
  0 siblings, 0 replies; 4+ messages in thread
From: Miquel Raynal @ 2022-10-18  9:56 UTC (permalink / raw)
  To: Rafał Miłecki, Miquel Raynal, Richard Weinberger,
	Vignesh Raghavendra
  Cc: ansuelsmth, linux-mtd, devicetree, linux-kernel, Rafał Miłecki

On Tue, 2022-10-04 at 08:37:10 UTC, =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= wrote:
> From: Rafał Miłecki <rafal@milecki.pl>
> 
> So far this feature was limited to the top-level "nvmem-cells" node.
> There are multiple parsers creating partitions and subpartitions
> dynamically. Extend that code to handle them too.
> 
> This allows finding partition-* node for every MTD (sub)partition.
> 
> Random example:
> 
> partitions {
> 	compatible = "brcm,bcm947xx-cfe-partitions";
> 
> 	partition-firmware {
> 		compatible = "brcm,trx";
> 
> 		partition-loader {
> 		};
> 	};
> };
> 
> Cc: Christian Marangi <ansuelsmth@gmail.com>
> Signed-off-by: Rafał Miłecki <rafal@milecki.pl>

Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git mtd/next, thanks.

Miquel

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

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

* Re: [PATCH V2 1/2] mtd: core: simplify (a bit) code find partition-matching dynamic OF node
  2022-10-04  8:37 [PATCH V2 1/2] mtd: core: simplify (a bit) code find partition-matching dynamic OF node Rafał Miłecki
  2022-10-04  8:37 ` [PATCH V2 2/2] mtd: core: try to find OF node for every MTD partition Rafał Miłecki
@ 2022-10-18  9:56 ` Miquel Raynal
  1 sibling, 0 replies; 4+ messages in thread
From: Miquel Raynal @ 2022-10-18  9:56 UTC (permalink / raw)
  To: Rafał Miłecki, Miquel Raynal, Richard Weinberger,
	Vignesh Raghavendra
  Cc: ansuelsmth, linux-mtd, devicetree, linux-kernel, Rafał Miłecki

On Tue, 2022-10-04 at 08:37:09 UTC, =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= wrote:
> 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()
> 3. Use mtd_get_of_node() helper
> 
> Cc: Christian Marangi <ansuelsmth@gmail.com>
> Signed-off-by: Rafał Miłecki <rafal@milecki.pl>

Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git mtd/next, thanks.

Miquel

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

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

end of thread, other threads:[~2022-10-18  9:57 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-04  8:37 [PATCH V2 1/2] mtd: core: simplify (a bit) code find partition-matching dynamic OF node Rafał Miłecki
2022-10-04  8:37 ` [PATCH V2 2/2] mtd: core: try to find OF node for every MTD partition Rafał Miłecki
2022-10-18  9:56   ` Miquel Raynal
2022-10-18  9:56 ` [PATCH V2 1/2] mtd: core: simplify (a bit) code find partition-matching dynamic OF node Miquel Raynal

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).