[PATCH 05/15] blk: host_dev: Sanity check on the size of host backing file

Bin Meng bmeng at tinylab.org
Tue Sep 26 10:43:35 CEST 2023


Since we are emulating a block device, its size should be multiple
of the configured block size.

Signed-off-by: Bin Meng <bmeng at tinylab.org>
---

 drivers/block/host_dev.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/block/host_dev.c b/drivers/block/host_dev.c
index 0b43f80a86..30c7415793 100644
--- a/drivers/block/host_dev.c
+++ b/drivers/block/host_dev.c
@@ -58,6 +58,11 @@ static int host_sb_attach_file(struct udevice *dev, const char *filename)
 
 	size = os_filesize(fd);
 	desc = dev_get_uclass_plat(blk);
+	if (size % desc->blksz) {
+		printf("The size of host backing file '%s' is not multiple of "
+		       "the device block size\n", filename);
+		goto err_fname;
+	}
 	desc->lba = size / desc->blksz;
 
 	/* write this in last, when nothing can go wrong */
-- 
2.25.1



More information about the U-Boot mailing list