[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v5 04/25] hw/char/sh_serial: Do not abort on invalid access
From: |
BALATON Zoltan |
Subject: |
[PATCH v5 04/25] hw/char/sh_serial: Do not abort on invalid access |
Date: |
Fri, 29 Oct 2021 18:23:36 +0200 |
Replace fprintf with qemu_log_mask LOG_GUEST_ERROR as the intention is
to handle valid accesses in these functions so if we get to these
errors then it's an invalid access. Do not abort as that would allow
the guest to crash QEMU and the practice in other devices is to not do
that just log and ignore the invalid access. While at it also simplify
the complex bit ops to check if a return value was set which can be
done much simpler and clearer.
Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
hw/char/sh_serial.c | 19 ++++++++++---------
1 file changed, 10 insertions(+), 9 deletions(-)
diff --git a/hw/char/sh_serial.c b/hw/char/sh_serial.c
index 053f45e1a6..2d6ea0042e 100644
--- a/hw/char/sh_serial.c
+++ b/hw/char/sh_serial.c
@@ -31,6 +31,7 @@
#include "chardev/char-fe.h"
#include "qapi/error.h"
#include "qemu/timer.h"
+#include "qemu/log.h"
#include "trace.h"
#define SH_SERIAL_FLAG_TEND (1 << 0)
@@ -195,17 +196,16 @@ static void sh_serial_write(void *opaque, hwaddr offs,
return;
}
}
-
- fprintf(stderr, "sh_serial: unsupported write to 0x%02"
- HWADDR_PRIx "\n", offs);
- abort();
+ qemu_log_mask(LOG_GUEST_ERROR,
+ "%s: unsupported write to 0x%02" HWADDR_PRIx "\n",
+ __func__, offs);
}
static uint64_t sh_serial_read(void *opaque, hwaddr offs,
unsigned size)
{
sh_serial_state *s = opaque;
- uint32_t ret = ~0;
+ uint32_t ret = UINT32_MAX;
#if 0
switch (offs) {
@@ -299,10 +299,11 @@ static uint64_t sh_serial_read(void *opaque, hwaddr offs,
}
trace_sh_serial_read(size, offs, ret);
- if (ret & ~((1 << 16) - 1)) {
- fprintf(stderr, "sh_serial: unsupported read from 0x%02"
- HWADDR_PRIx "\n", offs);
- abort();
+ if (ret > UINT16_MAX) {
+ qemu_log_mask(LOG_GUEST_ERROR,
+ "%s: unsupported read from 0x%02" HWADDR_PRIx "\n",
+ __func__, offs);
+ ret = 0;
}
return ret;
--
2.21.4
- [PATCH v5 00/25] More SH4 clean ups, BALATON Zoltan, 2021/10/29
- [PATCH v5 04/25] hw/char/sh_serial: Do not abort on invalid access,
BALATON Zoltan <=
- [PATCH v5 02/25] hw/sh4: Change debug printfs to traces, BALATON Zoltan, 2021/10/29
- [PATCH v5 06/25] hw/char/sh_serial: Embed QEMUTimer in state struct, BALATON Zoltan, 2021/10/29
- [PATCH v5 03/25] hw/sh4/r2d: Use error_report instead of fprintf to stderr, BALATON Zoltan, 2021/10/29
- [PATCH v5 18/25] hw/intc/sh_intc: Replace abort() with g_assert_not_reached(), BALATON Zoltan, 2021/10/29
- [PATCH v5 19/25] hw/intc/sh_intc: Avoid using continue in loops, BALATON Zoltan, 2021/10/29
- [PATCH v5 13/25] hw/intc/sh_intc: Drop another useless macro, BALATON Zoltan, 2021/10/29
- [PATCH v5 17/25] hw/intc/sh_intc: Inline and drop sh_intc_source() function, BALATON Zoltan, 2021/10/29
- [PATCH v5 12/25] hw/intc/sh_intc: Rename iomem region, BALATON Zoltan, 2021/10/29
- [PATCH v5 05/25] hw/char/sh_serial: Rename type sh_serial_state to SHSerialState, BALATON Zoltan, 2021/10/29
- [PATCH v5 11/25] hw/intc/sh_intc: Turn some defines into an enum, BALATON Zoltan, 2021/10/29