mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: "Uwe Kleine-König" <uwe@kleine-koenig.org>
To: barebox@lists.infradead.org
Cc: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
Subject: [PATCH 1/2] of: partition: Move some parts of of_fixup_partitions() into separate function
Date: Fri,  8 Mar 2024 10:15:08 +0100	[thread overview]
Message-ID: <20240308091507.249009-3-uwe@kleine-koenig.org> (raw)

From: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

This is a preparation for the next commit that fixes mtd partition
creation.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 drivers/of/partition.c | 81 ++++++++++++++++++++++++------------------
 1 file changed, 47 insertions(+), 34 deletions(-)

diff --git a/drivers/of/partition.c b/drivers/of/partition.c
index 7c9f443ee7bd..d11e1d1690f9 100644
--- a/drivers/of/partition.c
+++ b/drivers/of/partition.c
@@ -167,10 +167,55 @@ static void delete_subnodes(struct device_node *np)
 	}
 }
 
+static int of_fixup_one_partition(struct device_node *partnode, loff_t partoffset,
+				  loff_t size, const char *partname,
+				  unsigned int flags)
+{
+	int na, ns, len = 0;
+	char *name;
+	void *p;
+	u8 tmp[16 * 16]; /* Up to 64-bit address + 64-bit size */
+	struct device_node *part;
+	int ret;
+
+	name = basprintf("partition@%0llx", partoffset);
+	if (!name)
+		return -ENOMEM;
+
+	part = of_new_node(partnode, name);
+	free(name);
+	if (!part)
+		return -ENOMEM;
+
+	p = of_new_property(part, "label", partname, strlen(partname) + 1);
+	if (!p)
+		return -ENOMEM;
+
+	na = of_n_addr_cells(part);
+	ns = of_n_size_cells(part);
+
+	of_write_number(tmp + len, partoffset, na);
+	len += na * 4;
+	of_write_number(tmp + len, size, ns);
+	len += ns * 4;
+
+	ret = of_set_property(part, "reg", tmp, len, 1);
+	if (ret)
+		return ret;
+
+	if (flags & DEVFS_PARTITION_READONLY) {
+		ret = of_set_property(part, "read-only", NULL, 0, 1);
+		if (ret)
+			return ret;
+	}
+
+	return 0;
+}
+
 int of_fixup_partitions(struct device_node *np, struct cdev *cdev)
 {
 	struct cdev *partcdev;
-	struct device_node *part, *partnode;
+	struct device_node *partnode;
 	int ret;
 	int n_cells, n_parts = 0;
 
@@ -223,10 +268,6 @@ int of_fixup_partitions(struct device_node *np, struct cdev *cdev)
 		return ret;
 
 	list_for_each_entry(partcdev, &cdev->partitions, partition_entry) {
-		int na, ns, len = 0;
-		char *name;
-		void *p;
-		u8 tmp[16 * 16]; /* Up to 64-bit address + 64-bit size */
 		loff_t partoffset;
 
 		if (!(partcdev->flags & DEVFS_PARTITION_FROM_OF))
@@ -237,37 +278,9 @@ int of_fixup_partitions(struct device_node *np, struct cdev *cdev)
 		else
 			partoffset = partcdev->offset;
 
-		name = basprintf("partition@%0llx", partoffset);
-		if (!name)
-			return -ENOMEM;
-
-		part = of_new_node(partnode, name);
-		free(name);
-		if (!part)
-			return -ENOMEM;
-
-		p = of_new_property(part, "label", partcdev->partname,
-                                strlen(partcdev->partname) + 1);
-		if (!p)
-			return -ENOMEM;
-
-		na = of_n_addr_cells(part);
-		ns = of_n_size_cells(part);
-
-		of_write_number(tmp + len, partoffset, na);
-		len += na * 4;
-		of_write_number(tmp + len, partcdev->size, ns);
-		len += ns * 4;
-
-		ret = of_set_property(part, "reg", tmp, len, 1);
+		ret = of_fixup_one_partition(partnode, partoffset, partcdev->size, partcdev->partname, partcdev->flags);
 		if (ret)
 			return ret;
-
-		if (partcdev->flags & DEVFS_PARTITION_READONLY) {
-			ret = of_set_property(part, "read-only", NULL, 0, 1);
-			if (ret)
-				return ret;
-		}
 	}
 
 	return 0;

base-commit: ed7c14536d521793199abf0597164a46ba68e8e5
-- 
2.43.0




             reply	other threads:[~2024-03-08  9:15 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-08  9:15 Uwe Kleine-König [this message]
2024-03-08  9:15 ` [PATCH 2/2] of: partition: Use mtd partitioning for of_fixup instead of the cdev variant Uwe Kleine-König
2024-03-08  9:27   ` Ahmad Fatoum
2024-03-08 10:14     ` Uwe Kleine-König
2024-03-08 10:51       ` 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=20240308091507.249009-3-uwe@kleine-koenig.org \
    --to=uwe@kleine-koenig.org \
    --cc=barebox@lists.infradead.org \
    --cc=u.kleine-koenig@pengutronix.de \
    /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