All of lore.kernel.org
 help / color / mirror / Atom feed
From: Heinrich Schuchardt <xypron.debian@gmx.de>
To: u-boot@lists.denx.de
Subject: [PATCH 1/9] fs/fat/fat.c: Do not perform zero block reads if there are no blocks left
Date: Sat, 25 Jul 2020 17:27:38 +0200	[thread overview]
Message-ID: <539eec75-cd5b-86c1-d89f-c884bb0290f4@gmx.de> (raw)
In-Reply-To: <20200724215049.163379-2-jason.wessel@windriver.com>

On 7/24/20 11:50 PM, 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.

Our block drivers all have a different view on this:

mmc_read_blocks() is reading one block even if 0 blocks are requested.
scsi_setup_read16() happily passes the 0 to the controller.

I think blk_read_devnum(), blk_write_devnum(), blk_dread(), and
blk_dwrite() is where we need the block count check.

> ---------------------------------
> => fatls virtio 0:1
>        30   cmdline.txt
> => fatload virtio 0:1 ${loadaddr} cmdline.txt
> qemu-system-aarch64: virtio: zero sized buffers are not allowed
> ---------------------------------
>
> With the patch I get the expected results.
> ---------------------------------
> => fatls virtio 0:1
>        30   cmdline.txt
> => fatload virtio 0:1 ${loadaddr} cmdline.txt
> 30 bytes read in 11 ms (2 KiB/s)
> => md.b ${loadaddr} 0x1E
> 40080000: 64 77 63 5f 6f 74 67 2e 6c 70 6d 5f 65 6e 61 62    dwc_otg.lpm_enab
> 40080010: 6c 65 3d 30 20 72 6f 6f 74 77 61 69 74 0a          le=0 rootwait.
>
> ---------------------------------
>
> Signed-off-by: Jason Wessel <jason.wessel@windriver.com>
> Reviewed-by: Tom Rini <trini@konsulko.com>
> ---
>  fs/fat/fat.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/fs/fat/fat.c b/fs/fat/fat.c
> index 9578b74bae..28aa5aaa9f 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);

Using idx as variable name here for a block count is quite misleading.

Best regards

Heinrich

>  		if (ret != idx) {
>  			debug("Error reading data (got %d)\n", ret);
>  			return -1;
>

  reply	other threads:[~2020-07-25 15:27 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-24 21:50 [PULL][PATCH 0/9] Raspberry pi improvements qemu/usb/ethernet Jason Wessel
2020-07-24 21:50 ` [PATCH 1/9] fs/fat/fat.c: Do not perform zero block reads if there are no blocks left Jason Wessel
2020-07-25 15:27   ` Heinrich Schuchardt [this message]
2020-07-24 21:50 ` [PATCH 2/9] xhci: Add polling support for USB keyboards Jason Wessel
2020-07-24 21:50 ` [PATCH 3/9] usb_kbd: succeed even if no interrupt is pending Jason Wessel
2020-07-24 21:50 ` [PATCH 4/9] common/usb.c: Work around keyboard reporting "USB device not accepting new address" Jason Wessel
2020-07-24 21:50 ` [PATCH 5/9] xhci-ring.c: Add the poll_pend state to properly abort transactions Jason Wessel
2020-08-20  8:26   ` Bin Meng
2020-08-24  3:35     ` Jason Wessel
2020-07-24 21:50 ` [PATCH 6/9] xhci-ring: Fix crash when issuing "usb reset" Jason Wessel
2020-07-24 21:50 ` [PATCH 7/9] usb.c: Add a retry in the usb_prepare_device() Jason Wessel
2020-07-24 21:50 ` [PATCH 8/9] bcmgenet: fix DMA buffer management Jason Wessel
2020-07-24 21:50 ` [PATCH 9/9] bcmgenet: Add support for rgmii-rxid Jason Wessel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=539eec75-cd5b-86c1-d89f-c884bb0290f4@gmx.de \
    --to=xypron.debian@gmx.de \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.