Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

block: introduce add_disk_fwnode()

Introduce add_disk_fwnode() as a replacement of device_add_disk() that
permits to pass and attach a fwnode to disk dev.

This variant can be useful for eMMC that might have the partition table
for the disk defined in DT. A parser can later make use of the attached
fwnode to parse the related table and init the hardcoded partition for
the disk.

device_add_disk() is converted to a simple wrapper of add_disk_fwnode()
with the fwnode entry set as NULL.

Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Link: https://lore.kernel.org/r/20241002221306.4403-4-ansuelsmth@gmail.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Christian Marangi and committed by
Jens Axboe
9dfd9ea9 592e4dee

+27 -4
+24 -4
block/genhd.c
··· 383 383 } 384 384 385 385 /** 386 - * device_add_disk - add disk information to kernel list 386 + * add_disk_fwnode - add disk information to kernel list with fwnode 387 387 * @parent: parent device for the disk 388 388 * @disk: per-device partitioning information 389 389 * @groups: Additional per-device sysfs groups 390 + * @fwnode: attached disk fwnode 390 391 * 391 392 * This function registers the partitioning information in @disk 392 - * with the kernel. 393 + * with the kernel. Also attach a fwnode to the disk device. 393 394 */ 394 - int __must_check device_add_disk(struct device *parent, struct gendisk *disk, 395 - const struct attribute_group **groups) 395 + int __must_check add_disk_fwnode(struct device *parent, struct gendisk *disk, 396 + const struct attribute_group **groups, 397 + struct fwnode_handle *fwnode) 396 398 397 399 { 398 400 struct device *ddev = disk_to_dev(disk); ··· 454 452 ddev->parent = parent; 455 453 ddev->groups = groups; 456 454 dev_set_name(ddev, "%s", disk->disk_name); 455 + if (fwnode) 456 + device_set_node(ddev, fwnode); 457 457 if (!(disk->flags & GENHD_FL_HIDDEN)) 458 458 ddev->devt = MKDEV(disk->major, disk->first_minor); 459 459 ret = device_add(ddev); ··· 556 552 if (disk->queue->elevator) 557 553 elevator_exit(disk->queue); 558 554 return ret; 555 + } 556 + EXPORT_SYMBOL_GPL(add_disk_fwnode); 557 + 558 + /** 559 + * device_add_disk - add disk information to kernel list 560 + * @parent: parent device for the disk 561 + * @disk: per-device partitioning information 562 + * @groups: Additional per-device sysfs groups 563 + * 564 + * This function registers the partitioning information in @disk 565 + * with the kernel. 566 + */ 567 + int __must_check device_add_disk(struct device *parent, struct gendisk *disk, 568 + const struct attribute_group **groups) 569 + { 570 + return add_disk_fwnode(parent, disk, groups, NULL); 559 571 } 560 572 EXPORT_SYMBOL(device_add_disk); 561 573
+3
include/linux/blkdev.h
··· 725 725 #define for_each_bio(_bio) \ 726 726 for (; _bio; _bio = _bio->bi_next) 727 727 728 + int __must_check add_disk_fwnode(struct device *parent, struct gendisk *disk, 729 + const struct attribute_group **groups, 730 + struct fwnode_handle *fwnode); 728 731 int __must_check device_add_disk(struct device *parent, struct gendisk *disk, 729 732 const struct attribute_group **groups); 730 733 static inline int __must_check add_disk(struct gendisk *disk)