]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
blk: host_dev: Sanity check on the size of host backing file
authorBin Meng <bmeng@tinylab.org>
Tue, 26 Sep 2023 08:43:35 +0000 (16:43 +0800)
committerTom Rini <trini@konsulko.com>
Tue, 10 Oct 2023 20:19:43 +0000 (16:19 -0400)
Since we are emulating a block device, its size should be multiple
of the configured block size.

Signed-off-by: Bin Meng <bmeng@tinylab.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
drivers/block/host_dev.c

index 0b43f80a86431b61a7aa7c9341b432e0b2035fbc..30c74157934a53dfc81ce4159b49e59b2e9e6e39 100644 (file)
@@ -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 */