[PATCH 4/6] partition: switch to using cdevfs_add_partition

Ahmad Fatoum a.fatoum at pengutronix.de
Wed Jan 3 02:16:27 PST 2024


We already have a cdev, so it's wasteful to do a lookup by cdev name
using devfs_add_partition. Use the newly exported cdevfs_add_partition
helper directly instead.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 common/partitions.c    | 12 ++++++++----
 drivers/of/partition.c | 16 ++++++++--------
 2 files changed, 16 insertions(+), 12 deletions(-)

diff --git a/common/partitions.c b/common/partitions.c
index e3e8a9f3044d..8a245a1eee3d 100644
--- a/common/partitions.c
+++ b/common/partitions.c
@@ -32,17 +32,21 @@ static int register_one_partition(struct block_device *blk,
 {
 	char *partition_name;
 	int ret;
-	uint64_t start = part->first_sec * SECTOR_SIZE;
-	uint64_t size = part->size * SECTOR_SIZE;
 	struct cdev *cdev;
+	struct devfs_partition partinfo = {
+		.offset = part->first_sec * SECTOR_SIZE,
+		.size = part->size * SECTOR_SIZE,
+	};
 
 	partition_name = basprintf("%s.%d", blk->cdev.name, no);
 	if (!partition_name)
 		return -ENOMEM;
+
+	partinfo.name = partition_name;
+
 	dev_dbg(blk->dev, "Registering partition %s on drive %s (partuuid=%s)\n",
 				partition_name, blk->cdev.name, part->partuuid);
-	cdev = devfs_add_partition(blk->cdev.name,
-				start, size, 0, partition_name);
+	cdev = cdevfs_add_partition(&blk->cdev, &partinfo, NULL);
 	if (IS_ERR(cdev)) {
 		ret = PTR_ERR(cdev);
 		goto out;
diff --git a/drivers/of/partition.c b/drivers/of/partition.c
index 9b73419a83af..b91fe616d990 100644
--- a/drivers/of/partition.c
+++ b/drivers/of/partition.c
@@ -26,13 +26,12 @@ enum of_binding_name {
 
 struct cdev *of_parse_partition(struct cdev *cdev, struct device_node *node)
 {
+	struct devfs_partition partinfo = {};
 	const char *partname;
 	char *filename;
 	struct cdev *new;
 	const __be32 *reg;
-	u64 offset, size;
 	int len;
-	unsigned long flags = 0;
 	int na, ns;
 
 	if (!node)
@@ -50,8 +49,8 @@ struct cdev *of_parse_partition(struct cdev *cdev, struct device_node *node)
 		return NULL;
 	}
 
-	offset = of_read_number(reg, na);
-	size = of_read_number(reg + na, ns);
+	partinfo.offset = of_read_number(reg, na);
+	partinfo.size = of_read_number(reg + na, ns);
 
 	partname = of_get_property(node, "label", NULL);
 	if (!partname)
@@ -59,14 +58,15 @@ struct cdev *of_parse_partition(struct cdev *cdev, struct device_node *node)
 	if (!partname)
 		return NULL;
 
-	debug("add partition: %s.%s 0x%08llx 0x%08llx\n", cdev->name, partname, offset, size);
+	debug("add partition: %s.%s 0x%08llx 0x%08llx\n", cdev->name, partname,
+	      partinfo.offset, partinfo.size);
 
 	if (of_get_property(node, "read-only", NULL))
-		flags = DEVFS_PARTITION_READONLY;
+		partinfo.flags = DEVFS_PARTITION_READONLY;
 
-	filename = basprintf("%s.%s", cdev->name, partname);
+	partinfo.name = filename = basprintf("%s.%s", cdev->name, partname);
 
-	new = devfs_add_partition(cdev->name, offset, size, flags, filename);
+	new = cdevfs_add_partition(cdev, &partinfo, NULL);
 	if (IS_ERR(new)) {
 		pr_err("Adding partition %s failed: %pe\n", filename, new);
 		new = NULL;
-- 
2.39.2




More information about the barebox mailing list