[PATCH 05/14] of: partition: support 64bit partition sizes

Sascha Hauer s.hauer at pengutronix.de
Thu Mar 30 22:33:14 PDT 2017


Do not assume that #address-cells and #size-cells are
both 1. Parse them appropriately to support devices
> 4GuB.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/of/partition.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/drivers/of/partition.c b/drivers/of/partition.c
index f4d6c3322c..30df6b32d1 100644
--- a/drivers/of/partition.c
+++ b/drivers/of/partition.c
@@ -40,10 +40,11 @@ struct cdev *of_parse_partition(struct cdev *cdev, struct device_node *node)
 	char *filename;
 	struct cdev *new;
 	const __be32 *reg;
-	unsigned long offset, size;
+	u64 offset, size;
 	const char *name;
 	int len;
 	unsigned long flags = 0;
+	int na, ns;
 
 	if (!node)
 		return NULL;
@@ -52,8 +53,16 @@ struct cdev *of_parse_partition(struct cdev *cdev, struct device_node *node)
 	if (!reg)
 		return NULL;
 
-	offset = be32_to_cpu(reg[0]);
-	size = be32_to_cpu(reg[1]);
+	na = of_n_addr_cells(node);
+	ns = of_n_size_cells(node);
+
+	if (len < (na + ns) * sizeof(__be32)) {
+		pr_err("reg property too small in %s\n", node->full_name);
+		return NULL;
+	}
+
+	offset = of_read_number(reg, na);
+	size = of_read_number(reg + na, ns);
 
 	partname = of_get_property(node, "label", &len);
 	if (!partname)
@@ -63,7 +72,7 @@ struct cdev *of_parse_partition(struct cdev *cdev, struct device_node *node)
 
 	name = (char *)partname;
 
-	debug("add partition: %s.%s 0x%08lx 0x%08lx\n", cdev->name, partname, offset, size);
+	debug("add partition: %s.%s 0x%08llx 0x%08llx\n", cdev->name, partname, offset, size);
 
 	if (of_get_property(node, "read-only", &len))
 		flags = DEVFS_PARTITION_READONLY;
-- 
2.11.0




More information about the barebox mailing list