qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: Li Zhijian <lizhijian@cn.fujitsu.com>
Cc: qemu-devel@nongnu.org, peter.maydell@linaro.org,
	philip.li@intel.com, zhijianx.li@intel.com, philmd@redhat.com
Subject: Re: [Qemu-devel] [PATCH for-4.0 v4 2/4] refactor load_image_size
Date: Fri, 21 Dec 2018 11:12:06 -0500	[thread overview]
Message-ID: <20181221111136-mutt-send-email-mst@kernel.org> (raw)
In-Reply-To: <1544063533-10139-3-git-send-email-lizhijian@cn.fujitsu.com>

On Thu, Dec 06, 2018 at 10:32:11AM +0800, Li Zhijian wrote:
> Don't expect read(2) can always read as many as it's told.
> 
> Signed-off-by: Li Zhijian <lizhijian@cn.fujitsu.com>
> Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

This is more a theoretical bugfix than a refactoring right?

> ---
> V4: add reviewed-by tag
> ---
>  hw/core/loader.c | 11 +++++------
>  1 file changed, 5 insertions(+), 6 deletions(-)
> 
> diff --git a/hw/core/loader.c b/hw/core/loader.c
> index fa41842..9cbceab 100644
> --- a/hw/core/loader.c
> +++ b/hw/core/loader.c
> @@ -77,21 +77,20 @@ int64_t get_image_size(const char *filename)
>  ssize_t load_image_size(const char *filename, void *addr, size_t size)
>  {
>      int fd;
> -    ssize_t actsize;
> +    ssize_t actsize, l = 0;
>  
>      fd = open(filename, O_RDONLY | O_BINARY);
>      if (fd < 0) {
>          return -1;
>      }
>  
> -    actsize = read(fd, addr, size);
> -    if (actsize < 0) {
> -        close(fd);
> -        return -1;
> +    while ((actsize = read(fd, addr + l, size - l)) > 0) {
> +        l += actsize;
>      }
> +
>      close(fd);
>  
> -    return actsize;
> +    return actsize < 0 ? -1 : l;
>  }
>  
>  /* read()-like version */
> -- 
> 2.7.4

  reply	other threads:[~2018-12-21 16:12 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-06  2:32 [Qemu-devel] [PATCH for-4.0 v4 0/4] allow to load initrd below 4G for recent kernel Li Zhijian
2018-12-06  2:32 ` [Qemu-devel] [PATCH for-4.0 v4 1/4] unify len and addr type for memory/address APIs Li Zhijian
2019-01-07 10:04   ` Stefano Garzarella
2019-01-08  1:06     ` Li Zhijian
2018-12-06  2:32 ` [Qemu-devel] [PATCH for-4.0 v4 2/4] refactor load_image_size Li Zhijian
2018-12-21 16:12   ` Michael S. Tsirkin [this message]
2018-12-24  2:14     ` Li Zhijian
2019-01-07 10:33       ` Stefano Garzarella
2019-01-08  1:09         ` Li Zhijian
2018-12-06  2:32 ` [Qemu-devel] [PATCH for-4.0 v4 3/4] i386: import & use bootparam.h Li Zhijian
2018-12-21 16:04   ` Michael S. Tsirkin
2019-01-04 16:41   ` Stefano Garzarella
2019-01-08  1:11     ` Li Zhijian
2018-12-06  2:32 ` [Qemu-devel] [PATCH for-4.0 v4 4/4] i386: allow to load initrd below 4G for recent linux Li Zhijian
2018-12-21 16:10   ` Michael S. Tsirkin
2018-12-27 20:31     ` Eduardo Habkost
2018-12-28  7:20       ` Li Zhijian
2019-01-07 12:11       ` Stefano Garzarella
2019-01-09  6:22         ` Li Zhijian
2019-01-07 23:35       ` Paolo Bonzini
2018-12-21  1:37 ` [Qemu-devel] [PATCH for-4.0 v4 0/4] allow to load initrd below 4G for recent kernel Li Zhijian

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=20181221111136-mutt-send-email-mst@kernel.org \
    --to=mst@redhat.com \
    --cc=lizhijian@cn.fujitsu.com \
    --cc=peter.maydell@linaro.org \
    --cc=philip.li@intel.com \
    --cc=philmd@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=zhijianx.li@intel.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).