[PATCH v9 05/10] block: partitions: of: Attach partition fwnode to the block device
Loic Poulain <[email protected]> Thu, 30 Jul 2026 18:00:35 +0200
| Newsgroups | org.infradead.lists.ath10k,org.kernel.vger.linux-arm-msm,org.kernel.vger.linux-block,org.kernel.vger.linux-bluetooth,org.kernel.vger.linux-devicetree,org.kernel.vger.linux-kernel,org.kernel.vger.linux-mmc,org.kernel.vger.linux-wireless,org.kernel.vger.netdev |
|---|---|
| Message-ID | <[email protected]> |
The OF partition parser reads offset, size and label from each "fixed-partitions" child node but does not associate that node with the resulting partition block device. As a result a partition has no of_node, unlike the whole-disk device which gets its firmware node via add_disk_fwnode(). Carry the partition's device tree node through the parser and attach it to the partition's block device with device_set_node(), mirroring the whole-disk case. This lets consumers describe per-partition properties in the device tree (for example an NVMEM layout on a partition node) and look them up through the partition device. No functional change for existing users, partitions without a matching device tree node simply get a NULL fwnode. Signed-off-by: Loic Poulain <[email protected]> --- block/partitions/check.h | 1 + block/partitions/core.c | 10 +++++++--- block/partitions/of.c | 3 +++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/block/partitions/check.h b/block/partitions/check.h index b0997467b61a54a8a621b9c155c8329289649460..326081499d9a6be730dbd659c110449cfa06921f 100644 --- a/block/partitions/check.h +++ b/block/partitions/check.h @@ -17,6 +17,7 @@ struct parsed_partitions { int flags; bool has_info; struct partition_meta_info info; + struct fwnode_handle *fwnode; } *parts; int next; int limit; diff --git a/block/partitions/core.c b/block/partitions/core.c index b5c59b79ca7cbb28d4d93478ee1c80908f76ee9f..72f435dfeffc63e897913571f319e5edd8e7ba88 100644 --- a/block/partitions/core.c +++ b/block/partitions/core.c @@ -11,6 +11,7 @@ #include <linux/sysfs.h> #include <linux/ctype.h> #include <linux/vmalloc.h> +#include <linux/property.h> #include <linux/raid/detect.h> #include "check.h" @@ -247,6 +248,7 @@ static const struct attribute_group *part_attr_groups[] = { static void part_release(struct device *dev) { + fwnode_handle_put(dev_fwnode(dev)); put_disk(dev_to_bdev(dev)->bd_disk); bdev_drop(dev_to_bdev(dev)); } @@ -294,7 +296,8 @@ static const DEVICE_ATTR(whole_disk, 0444, whole_disk_show, NULL); */ static struct block_device *add_partition(struct gendisk *disk, int partno, sector_t start, sector_t len, int flags, - struct partition_meta_info *info) + struct partition_meta_info *info, + struct fwnode_handle *fwnode) { dev_t devt = MKDEV(0, 0); struct device *ddev = disk_to_dev(disk); @@ -343,6 +346,7 @@ static struct block_device *add_partition(struct gendisk *disk, int partno, pdev->class = &block_class; pdev->type = &part_type; pdev->parent = ddev; + device_set_node(pdev, fwnode); /* in consecutive minor range? */ if (bdev_partno(bdev) < disk->minors) { @@ -449,7 +453,7 @@ int bdev_add_partition(struct gendisk *disk, int partno, sector_t start, } part = add_partition(disk, partno, start, length, - ADDPART_FLAG_NONE, NULL); + ADDPART_FLAG_NONE, NULL, NULL); ret = PTR_ERR_OR_ZERO(part); out: mutex_unlock(&disk->open_mutex); @@ -564,7 +568,7 @@ static bool blk_add_partition(struct gendisk *disk, } part = add_partition(disk, p, from, size, state->parts[p].flags, - &state->parts[p].info); + &state->parts[p].info, state->parts[p].fwnode); if (IS_ERR(part)) { if (PTR_ERR(part) != -ENXIO) { printk(KERN_ERR " %s: p%d could not be added: %pe\n", diff --git a/block/partitions/of.c b/block/partitions/of.c index dab36513eba336344c9558d486a8915624b0fca8..d4016f9b77ec078eb1adb32923107c012ca4a751 100644 --- a/block/partitions/of.c +++ b/block/partitions/of.c @@ -3,6 +3,7 @@ #include <linux/blkdev.h> #include <linux/major.h> #include <linux/of.h> +#include <linux/property.h> #include <linux/string.h> #include "check.h" @@ -65,6 +66,8 @@ static void add_of_partition(struct parsed_partitions *state, int slot, partname = of_get_property(np, "name", &len); strscpy(info->volname, partname, sizeof(info->volname)); + state->parts[slot].fwnode = fwnode_handle_get(of_fwnode_handle(np)); + seq_buf_printf(&state->pp_buf, "(%s)", info->volname); } -- 2.34.1