summaryrefslogtreecommitdiffstats
path: root/hw/misc
diff options
context:
space:
mode:
authorGreen Wan2020-11-04 10:29:00 +0100
committerAlistair Francis2021-01-16 19:57:21 +0100
commit29b5fe0dcd512f9829475e3eb3f6fdc5e293b8f0 (patch)
tree9c50c04b41d09ac3d50e93c1940a36f5ee77056e /hw/misc
parenthw/riscv: sifive_u: Use SIFIVE_U_CPU for mc->default_cpu_type (diff)
downloadqemu-29b5fe0dcd512f9829475e3eb3f6fdc5e293b8f0.tar.gz
qemu-29b5fe0dcd512f9829475e3eb3f6fdc5e293b8f0.tar.xz
qemu-29b5fe0dcd512f9829475e3eb3f6fdc5e293b8f0.zip
hw/misc/sifive_u_otp: handling the fails of blk_pread and blk_pwrite
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. Fixes: Coverity CID 1435959 Fixes: Coverity CID 1435960 Fixes: Coverity CID 1435961 Signed-off-by: Green Wan <green.wan@sifive.com> Reviewed-by: Alistair Francis <alistair.francis@wdc.com> Message-id: 20201104092900.21214-1-green.wan@sifive.com Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
Diffstat (limited to 'hw/misc')
-rw-r--r--hw/misc/sifive_u_otp.c31
1 files changed, 23 insertions, 8 deletions
diff --git a/hw/misc/sifive_u_otp.c b/hw/misc/sifive_u_otp.c
index 4401787a5c..f921c67644 100644
--- a/hw/misc/sifive_u_otp.c
+++ b/hw/misc/sifive_u_otp.c
@@ -63,8 +63,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;
}
@@ -161,8 +166,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 */
@@ -249,12 +258,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 */