Message ID | 20200623213654.125207-1-jason.wessel@windriver.com |
---|---|
State | Accepted |
Commit | 5b3ddb17baec13b4386620b533527d0f53ddeddf |
Headers | show |
Series | [v3] fs/fat/fat.c: Do not perform zero block reads if there are no blocks left | expand |
On Tue, Jun 23, 2020 at 02:36:54PM -0700, Jason Wessel wrote: > While using u-boot with qemu's virtio driver I stumbled across a > problem reading files less than sector size. On the real hardware the > block reader seems ok with reading zero blocks, and while we could fix > the virtio host side of qemu to deal with a zero block read instead of > crashing, the u-boot fat driver should not be doing zero block reads > in the first place. If you ask hardware to read zero blocks you are > just going to get zero data. There may also be other hardware that > responds similarly to the virtio interface so this is worth fixing. > > Without the patch I get the following and have to restart qemu because > it dies. Reviewed-by: Tom Rini <trini at konsulko.com>
On Tue, Jun 23, 2020 at 02:36:54PM -0700, Jason Wessel wrote: > While using u-boot with qemu's virtio driver I stumbled across a > problem reading files less than sector size. On the real hardware the > block reader seems ok with reading zero blocks, and while we could fix > the virtio host side of qemu to deal with a zero block read instead of > crashing, the u-boot fat driver should not be doing zero block reads > in the first place. If you ask hardware to read zero blocks you are > just going to get zero data. There may also be other hardware that > responds similarly to the virtio interface so this is worth fixing. > > Without the patch I get the following and have to restart qemu because > it dies. Applied to u-boot/master, thanks! -- Tom
diff --git a/fs/fat/fat.c b/fs/fat/fat.c index 7fd29470c1..dfad1e910b 100644 --- a/fs/fat/fat.c +++ b/fs/fat/fat.c @@ -278,7 +278,10 @@ get_cluster(fsdata *mydata, __u32 clustnum, __u8 *buffer, unsigned long size) } } else { idx = size / mydata->sect_size; - ret = disk_read(startsect, idx, buffer); + if (idx == 0) + ret = 0; + else + ret = disk_read(startsect, idx, buffer); if (ret != idx) { debug("Error reading data (got %d)\n", ret); return -1;