[PATCH 3/8] disk: Simplify disk_blk_{write, erase}() using blk_{write, erase}()

Marek Vasut marek.vasut+renesas at mailbox.org
Mon Aug 14 01:46:43 CEST 2023


These two functions are basically identical, just call the blk_*()
functions from disk_blk_*() functions. The only difference is that
the disk_blk_*() functions have to use parent block device as the
udevice implementing block device operations.

Add documentation on what those functions really do. The documentation
is not wrong even though it likely does look that way. The write/erase
functions really do not take into account the partition offset. This
will be fixed in the next patch.

Signed-off-by: Marek Vasut <marek.vasut+renesas at mailbox.org>
---
Cc: AKASHI Takahiro <takahiro.akashi at linaro.org>
Cc: Abdellatif El Khlifi <abdellatif.elkhlifi at arm.com>
Cc: Bin Meng <bmeng.cn at gmail.com>
Cc: Heinrich Schuchardt <xypron.glplk at gmx.de>
Cc: Joshua Watt <jpewhacker at gmail.com>
Cc: Michal Suchanek <msuchanek at suse.de>
Cc: Simon Glass <sjg at chromium.org>
Cc: Tobias Waldekranz <tobias at waldekranz.com>
---
 disk/disk-uclass.c | 66 ++++++++++++++++------------------------------
 1 file changed, 23 insertions(+), 43 deletions(-)

diff --git a/disk/disk-uclass.c b/disk/disk-uclass.c
index 6daece1288f..5cb1594e015 100644
--- a/disk/disk-uclass.c
+++ b/disk/disk-uclass.c
@@ -149,25 +149,6 @@ U_BOOT_DRIVER(blk_partition) = {
 /*
  * BLOCK IO APIs
  */
-static struct blk_desc *dev_get_blk(struct udevice *dev)
-{
-	struct blk_desc *desc;
-
-	switch (device_get_uclass_id(dev)) {
-	/*
-	 * We won't support UCLASS_BLK with dev_* interfaces.
-	 */
-	case UCLASS_PARTITION:
-		desc = dev_get_uclass_plat(dev_get_parent(dev));
-		break;
-	default:
-		desc = NULL;
-		break;
-	}
-
-	return desc;
-}
-
 /**
  * disk_blk_read() - Read from a block device partition
  *
@@ -190,42 +171,41 @@ unsigned long disk_blk_read(struct udevice *dev, lbaint_t start,
 			blkcnt, buffer);
 }
 
+/**
+ * disk_blk_write() - Write to a block device
+ *
+ * @dev: Device to write to
+ * @start: Start block for the write
+ * @blkcnt: Number of blocks to write
+ * @buffer: Data to write
+ * @return number of blocks written (which may be less than @blkcnt),
+ * or -ve on error. This never returns 0 unless @blkcnt is 0
+ */
 unsigned long disk_blk_write(struct udevice *dev, lbaint_t start,
 			     lbaint_t blkcnt, const void *buffer)
 {
-	struct blk_desc *desc;
-	const struct blk_ops *ops;
-
-	desc = dev_get_blk(dev);
-	if (!desc)
-		return -ENOSYS;
-
-	ops = blk_get_ops(dev);
-	if (!ops->write)
+	if (device_get_uclass_id(dev) != UCLASS_PARTITION)
 		return -ENOSYS;
 
-	blkcache_invalidate(desc->uclass_id, desc->devnum);
-
-	return ops->write(dev, start, blkcnt, buffer);
+	return blk_write(dev_get_parent(dev), start, blkcnt, buffer);
 }
 
+/**
+ * disk_blk_erase() - Erase part of a block device
+ *
+ * @dev: Device to erase
+ * @start: Start block for the erase
+ * @blkcnt: Number of blocks to erase
+ * @return number of blocks erased (which may be less than @blkcnt),
+ * or -ve on error. This never returns 0 unless @blkcnt is 0
+ */
 unsigned long disk_blk_erase(struct udevice *dev, lbaint_t start,
 			     lbaint_t blkcnt)
 {
-	struct blk_desc *desc;
-	const struct blk_ops *ops;
-
-	desc = dev_get_blk(dev);
-	if (!desc)
-		return -ENOSYS;
-
-	ops = blk_get_ops(dev);
-	if (!ops->erase)
+	if (device_get_uclass_id(dev) != UCLASS_PARTITION)
 		return -ENOSYS;
 
-	blkcache_invalidate(desc->uclass_id, desc->devnum);
-
-	return ops->erase(dev, start, blkcnt);
+	return blk_erase(dev_get_parent(dev), start, blkcnt);
 }
 
 UCLASS_DRIVER(partition) = {
-- 
2.40.1



More information about the U-Boot mailing list