qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@redhat.com>
To: Mansour Ahmadi <mansourweb@gmail.com>,
	qemu-devel@nongnu.org, Qemu-block <qemu-block@nongnu.org>
Subject: Re: [PATCH] When updating the PFLASH file contents, we should check for a possible failure of blk_pwrite(). Similar to 3a68829 commit
Date: Wed, 8 Apr 2020 10:08:00 +0200	[thread overview]
Message-ID: <34044154-1982-6f43-d124-bc4bc3924136@redhat.com> (raw)
In-Reply-To: <20200408003552.58095-1-mansourweb@gmail.com>

Hi Mansour,

On 4/8/20 2:35 AM, Mansour Ahmadi wrote:
> Signed-off-by: Mansour Ahmadi <mansourweb@gmail.com>
> ---
>   hw/block/pflash_cfi01.c | 6 +++++-
>   hw/block/pflash_cfi02.c | 6 +++++-
>   2 files changed, 10 insertions(+), 2 deletions(-)
> 
> diff --git a/hw/block/pflash_cfi01.c b/hw/block/pflash_cfi01.c
> index 24f3bce7ef..31319cfd07 100644
> --- a/hw/block/pflash_cfi01.c
> +++ b/hw/block/pflash_cfi01.c
> @@ -399,13 +399,17 @@ static void pflash_update(PFlashCFI01 *pfl, int offset,
>                             int size)
>   {
>       int offset_end;
> +    int ret;
>       if (pfl->blk) {
>           offset_end = offset + size;
>           /* widen to sector boundaries */
>           offset = QEMU_ALIGN_DOWN(offset, BDRV_SECTOR_SIZE);
>           offset_end = QEMU_ALIGN_UP(offset_end, BDRV_SECTOR_SIZE);
> -        blk_pwrite(pfl->blk, offset, pfl->storage + offset,
> +        ret = blk_pwrite(pfl->blk, offset, pfl->storage + offset,
>                      offset_end - offset, 0);
> +	if (ret < 0) {
> +            error_report("Could not update PFLASH: %s", strerror(-ret));

Thanks for your patch. Note that it doesn't compile:

hw/block/pflash_cfi01.c:411:6: error: implicit declaration of function 
'error_report' [-Werror=implicit-function-declaration]
       error_report("Could not update PFLASH: %s", strerror(-ret));
       ^

Better than reporting the error is to set the error flag in the status 
register.

> +        }
>       }
>   }
>   
> diff --git a/hw/block/pflash_cfi02.c b/hw/block/pflash_cfi02.c
> index 12f18d401a..fee5b3497c 100644
> --- a/hw/block/pflash_cfi02.c
> +++ b/hw/block/pflash_cfi02.c
> @@ -393,13 +393,17 @@ static uint64_t pflash_read(void *opaque, hwaddr offset, unsigned int width)
>   static void pflash_update(PFlashCFI02 *pfl, int offset, int size)
>   {
>       int offset_end;
> +    int ret;
>       if (pfl->blk) {
>           offset_end = offset + size;
>           /* widen to sector boundaries */
>           offset = QEMU_ALIGN_DOWN(offset, BDRV_SECTOR_SIZE);
>           offset_end = QEMU_ALIGN_UP(offset_end, BDRV_SECTOR_SIZE);
> -        blk_pwrite(pfl->blk, offset, pfl->storage + offset,
> +        ret = blk_pwrite(pfl->blk, offset, pfl->storage + offset,
>                      offset_end - offset, 0);
> +	if (ret < 0) {
> +	    error_report("Could not update PFLASH: %s", strerror(-ret));
> +        }

Similar comments (does not compile, set error status register).

>       }
>   }
>   
> 



  parent reply	other threads:[~2020-04-08  8:11 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-08  0:35 [PATCH] When updating the PFLASH file contents, we should check for a possible failure of blk_pwrite(). Similar to 3a68829 commit Mansour Ahmadi
2020-04-08  6:36 ` no-reply
2020-04-08  6:39 ` no-reply
2020-04-08  6:44 ` no-reply
2020-04-08  8:08 ` Philippe Mathieu-Daudé [this message]
2020-04-12 21:35   ` Philippe Mathieu-Daudé

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=34044154-1982-6f43-d124-bc4bc3924136@redhat.com \
    --to=philmd@redhat.com \
    --cc=mansourweb@gmail.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /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).