[PATCH 1/2] of: partition: Move some parts of of_fixup_partitions() into separate function

Uwe Kleine-König uwe at kleine-koenig.org
Fri Mar 8 01:15:08 PST 2024


From: Uwe Kleine-König <u.kleine-koenig at 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 at 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




More information about the barebox mailing list