qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Cédric Le Goater" <clg@redhat.com>
To: BALATON Zoltan <balaton@eik.bme.hu>,
	qemu-devel@nongnu.org, qemu-ppc@nongnu.org
Cc: Nicholas Piggin <npiggin@gmail.com>
Subject: Re: [PATCH] ppc/amigaone: Check blk_pwrite return value
Date: Mon, 17 Mar 2025 08:06:22 +0100	[thread overview]
Message-ID: <30852eb7-ef37-4da1-b014-ad4131d74c29@redhat.com> (raw)
In-Reply-To: <20250314200140.2DBE74E6069@zero.eik.bme.hu>

On 3/14/25 21:01, BALATON Zoltan wrote:
> Coverity reported that return value of blk_pwrite() maybe should not
> be ignored. We can't do much if this happens other than report an
> error but let's do that to silence this report.
> 
> Resolves: Coverity CID 1593725
> Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu>
> ---
>   hw/ppc/amigaone.c | 14 ++++++++------
>   1 file changed, 8 insertions(+), 6 deletions(-)
> 
> diff --git a/hw/ppc/amigaone.c b/hw/ppc/amigaone.c
> index 483512125f..5d787c3059 100644
> --- a/hw/ppc/amigaone.c
> +++ b/hw/ppc/amigaone.c
> @@ -108,8 +108,8 @@ static void nvram_write(void *opaque, hwaddr addr, uint64_t val,
>       uint8_t *p = memory_region_get_ram_ptr(&s->mr);

why is the nvram never read ?

>   
>       p[addr] = val;
> -    if (s->blk) {
> -        blk_pwrite(s->blk, addr, 1, &val, 0);
> +    if (s->blk && blk_pwrite(s->blk, addr, 1, &val, 0) < 0) {
> +        error_report("%s: could not write %s", __func__, blk_name(s->blk));

hmm, guest_error maybe ? since this is a runtime error.

>       }
>   }
>   
> @@ -151,15 +151,17 @@ static void nvram_realize(DeviceState *dev, Error **errp)
>           *c = cpu_to_be32(CRC32_DEFAULT_ENV);
>           /* Also copies terminating \0 as env is terminated by \0\0 */
>           memcpy(p + 4, default_env, sizeof(default_env));
> -        if (s->blk) {
> -            blk_pwrite(s->blk, 0, sizeof(crc) + sizeof(default_env), p, 0);
> +        if (s->blk &&
> +            blk_pwrite(s->blk, 0, sizeof(crc) + sizeof(default_env), p, 0) < 0
> +           ) {
> +            error_report("%s: could not write %s", __func__, blk_name(s->blk));

This should use the errp parameter.

>           }
>           return;
>       }
>       if (*c == 0) {
>           *c = cpu_to_be32(crc32(0, p + 4, NVRAM_SIZE - 4));
> -        if (s->blk) {
> -            blk_pwrite(s->blk, 0, 4, p, 0);
> +        if (s->blk && blk_pwrite(s->blk, 0, 4, p, 0) < 0) {
> +            error_report("%s: could not write %s", __func__, blk_name(s->blk));

same here.

Thanks,

C.



>           }
>       }
>       if (be32_to_cpu(*c) != crc) {



  parent reply	other threads:[~2025-03-17  7:06 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-14 20:01 [PATCH] ppc/amigaone: Check blk_pwrite return value BALATON Zoltan
2025-03-17  4:21 ` Nicholas Piggin
2025-03-17  7:06 ` Cédric Le Goater [this message]
2025-03-17 13:13   ` BALATON Zoltan
2025-03-20 10:03     ` Nicholas Piggin

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=30852eb7-ef37-4da1-b014-ad4131d74c29@redhat.com \
    --to=clg@redhat.com \
    --cc=balaton@eik.bme.hu \
    --cc=npiggin@gmail.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@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).