mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 5/6] of: partition: refactor of_partition_binding checks into switch
Date: Mon, 17 Feb 2025 19:08:32 +0100	[thread overview]
Message-ID: <20250217180833.3955657-6-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20250217180833.3955657-1-a.fatoum@pengutronix.de>

We are going to add a new fixup mode to enum of_binding_name in the next
commit. For readability's sake, refactor the existing code to make it
easier to extend.

No functional change.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 drivers/of/partition.c | 36 +++++++++++++++++++++---------------
 1 file changed, 21 insertions(+), 15 deletions(-)

diff --git a/drivers/of/partition.c b/drivers/of/partition.c
index 4f966d900f1f..fa4847e20a2b 100644
--- a/drivers/of/partition.c
+++ b/drivers/of/partition.c
@@ -18,6 +18,14 @@
 
 static unsigned int of_partition_binding;
 
+/**
+ * enum of_binding_name - Name of binding to use for OF partition fixup
+ * @MTD_OF_BINDING_NEW:		Fix up new-style partition bindings
+ *				with compatible = "fixed-partitions" container
+ * @MTD_OF_BINDING_LEGACY:	Fix up legacy partition bindings
+ *				directly into the parent node without container
+ * @MTD_OF_BINDING_DONTTOUCH:	Don't touch partition nodes at all - no fixups
+ */
 enum of_binding_name {
 	MTD_OF_BINDING_NEW,
 	MTD_OF_BINDING_LEGACY,
@@ -185,28 +193,26 @@ int of_fixup_partitions(struct device_node *np, struct cdev *cdev)
 		n_cells = 1;
 
 	partnode = of_get_child_by_name(np, "partitions");
-	if (partnode) {
-		if (of_partition_binding == MTD_OF_BINDING_LEGACY) {
-			of_delete_node(partnode);
-			partnode = np;
-		}
-		delete_subnodes(partnode);
-	} else {
-		delete_subnodes(np);
 
-		if (of_partition_binding == MTD_OF_BINDING_LEGACY)
-			partnode = np;
-		else
-			partnode = of_new_node(np, "partitions");
-	}
-
-	if (of_partition_binding == MTD_OF_BINDING_NEW) {
+	switch (of_partition_binding) {
+	case MTD_OF_BINDING_LEGACY:
+		of_delete_node(partnode);
+		partnode = np;
+		break;
+	case MTD_OF_BINDING_NEW:
+		partnode = partnode ?: of_new_node(np, "partitions");
 		ret = of_property_write_string(partnode, "compatible",
 					       "fixed-partitions");
 		if (ret)
 			return ret;
+		break;
 	}
 
+	if (partnode)
+		delete_subnodes(partnode);
+	else
+		delete_subnodes(np);
+
 	ret = of_property_write_u32(partnode, "#size-cells", n_cells);
 	if (ret)
 		return ret;
-- 
2.39.5




  parent reply	other threads:[~2025-02-17 18:23 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-17 18:08 [PATCH 0/6] of: partition: add Linux CONFIG_OF_PARTITION-compatible adaptive fixup mode Ahmad Fatoum
2025-02-17 18:08 ` [PATCH 1/6] of: factor out of_node_is_fixed_partitions check Ahmad Fatoum
2025-02-17 18:08 ` [PATCH 2/6] of: of_path: support barebox,fixed-partitions Ahmad Fatoum
2025-02-17 18:08 ` [PATCH 3/6] ARM: IMX8MP: var-dart-dt8mcustomboard.dts: use new-style partition binding Ahmad Fatoum
2025-02-17 18:08 ` [PATCH 4/6] ARM: dts: prefix all non-MTD fixed-partitions with barebox, Ahmad Fatoum
2025-02-17 18:08 ` Ahmad Fatoum [this message]
2025-02-17 18:08 ` [PATCH 6/6] of: partition: add Linux CONFIG_OF_PARTITION-compatible adaptive fixup mode Ahmad Fatoum
2025-02-17 19:25 ` [PATCH 0/6] " Marco Felsch
2025-02-17 19:57   ` Ahmad Fatoum
2025-02-20  8:26 ` Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250217180833.3955657-6-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox