From: Peter Maydell <peter.maydell@linaro.org>
To: Green Wan <green.wan@sifive.com>
Cc: Alistair Francis <alistair23@gmail.com>,
Bin Meng <bmeng.cn@gmail.com>,
QEMU Developers <qemu-devel@nongnu.org>
Subject: Re: [PATCH] hw/misc/sifive_u_otp: handling the fails of blk_pread and blk_pwrite
Date: Fri, 15 Jan 2021 11:50:45 +0000 [thread overview]
Message-ID: <CAFEAcA_EykbnmTQuz4RT3qGMt-Atf=EAdaHd-QqBvJCPvwemqA@mail.gmail.com> (raw)
In-Reply-To: <20201104092900.21214-1-green.wan@sifive.com>
Ping! This patch was trying to fix a Coverity issue (CID 1435959,
1435960, 1435961) -- is anybody planning to review it?
(I'm not entirely sure 'guest error' is the right warning category,
but I don't know the specifics of this device.)
thanks
-- PMM
On Wed, 4 Nov 2020 at 09:29, Green Wan <green.wan@sifive.com> wrote:
>
> Fix code coverage issues by checking return value and handling fail case
> of blk_pread() and blk_pwrite(). Return default value 0xff if read fails.
>
> Signed-off-by: Green Wan <green.wan@sifive.com>
> ---
> hw/misc/sifive_u_otp.c | 31 +++++++++++++++++++++++--------
> 1 file changed, 23 insertions(+), 8 deletions(-)
>
> diff --git a/hw/misc/sifive_u_otp.c b/hw/misc/sifive_u_otp.c
> index 60066375ab..4314727d0d 100644
> --- a/hw/misc/sifive_u_otp.c
> +++ b/hw/misc/sifive_u_otp.c
> @@ -62,8 +62,13 @@ static uint64_t sifive_u_otp_read(void *opaque, hwaddr addr, unsigned int size)
> if (s->blk) {
> int32_t buf;
>
> - blk_pread(s->blk, s->pa * SIFIVE_U_OTP_FUSE_WORD, &buf,
> - SIFIVE_U_OTP_FUSE_WORD);
> + if (blk_pread(s->blk, s->pa * SIFIVE_U_OTP_FUSE_WORD, &buf,
> + SIFIVE_U_OTP_FUSE_WORD) < 0) {
> + qemu_log_mask(LOG_GUEST_ERROR,
> + "read error index<%d>\n", s->pa);
> + return 0xff;
> + }
> +
> return buf;
> }
>
> @@ -160,8 +165,12 @@ static void sifive_u_otp_write(void *opaque, hwaddr addr,
>
> /* write to backend */
> if (s->blk) {
> - blk_pwrite(s->blk, s->pa * SIFIVE_U_OTP_FUSE_WORD,
> - &s->fuse[s->pa], SIFIVE_U_OTP_FUSE_WORD, 0);
> + if (blk_pwrite(s->blk, s->pa * SIFIVE_U_OTP_FUSE_WORD,
> + &s->fuse[s->pa], SIFIVE_U_OTP_FUSE_WORD,
> + 0) < 0) {
> + qemu_log_mask(LOG_GUEST_ERROR,
> + "write error index<%d>\n", s->pa);
> + }
> }
>
> /* update written bit */
> @@ -248,12 +257,18 @@ static void sifive_u_otp_reset(DeviceState *dev)
> int index = SIFIVE_U_OTP_SERIAL_ADDR;
>
> serial_data = s->serial;
> - blk_pwrite(s->blk, index * SIFIVE_U_OTP_FUSE_WORD,
> - &serial_data, SIFIVE_U_OTP_FUSE_WORD, 0);
> + if (blk_pwrite(s->blk, index * SIFIVE_U_OTP_FUSE_WORD,
> + &serial_data, SIFIVE_U_OTP_FUSE_WORD, 0) < 0) {
> + qemu_log_mask(LOG_GUEST_ERROR,
> + "write error index<%d>\n", index);
> + }
>
> serial_data = ~(s->serial);
> - blk_pwrite(s->blk, (index + 1) * SIFIVE_U_OTP_FUSE_WORD,
> - &serial_data, SIFIVE_U_OTP_FUSE_WORD, 0);
> + if (blk_pwrite(s->blk, (index + 1) * SIFIVE_U_OTP_FUSE_WORD,
> + &serial_data, SIFIVE_U_OTP_FUSE_WORD, 0) < 0) {
> + qemu_log_mask(LOG_GUEST_ERROR,
> + "write error index<%d>\n", index + 1);
> + }
> }
>
> /* Initialize write-once map */
> --
> 2.17.1
next prev parent reply other threads:[~2021-01-15 11:51 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-04 9:29 [PATCH] hw/misc/sifive_u_otp: handling the fails of blk_pread and blk_pwrite Green Wan
2021-01-15 11:50 ` Peter Maydell [this message]
2021-01-15 13:33 ` Bin Meng
2021-01-15 13:55 ` Peter Maydell
2021-01-15 14:09 ` Bin Meng
2021-01-15 21:43 ` Alistair Francis
2021-01-15 22:17 ` Peter Maydell
2021-01-15 23:05 ` Alistair Francis
2021-01-15 21:56 ` Alistair Francis
2021-01-15 21:41 ` Alistair Francis
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='CAFEAcA_EykbnmTQuz4RT3qGMt-Atf=EAdaHd-QqBvJCPvwemqA@mail.gmail.com' \
--to=peter.maydell@linaro.org \
--cc=alistair23@gmail.com \
--cc=bmeng.cn@gmail.com \
--cc=green.wan@sifive.com \
--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).