[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 09/30] hw/char/sh_serial: Do not abort on invalid access
From: |
Philippe Mathieu-Daudé |
Subject: |
[PULL 09/30] hw/char/sh_serial: Do not abort on invalid access |
Date: |
Sat, 30 Oct 2021 19:05:54 +0200 |
From: BALATON Zoltan <balaton@eik.bme.hu>
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>
Message-Id:
<6b46045141d6d9cc32e17c223896fa1116384796.1635541329.git.balaton@eik.bme.hu>
Signed-off-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 053f45e1a62..2d6ea0042ed 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.31.1
- [PULL 00/30] Renesas SH-4 patches for 2021-10-30, Philippe Mathieu-Daudé, 2021/10/30
- [PULL 01/30] hw/sh4: Coding style: Remove tabs, Philippe Mathieu-Daudé, 2021/10/30
- [PULL 02/30] hw/sh4: Coding style: Fix multi-line comments, Philippe Mathieu-Daudé, 2021/10/30
- [PULL 03/30] hw/sh4: Coding style: White space fixes, Philippe Mathieu-Daudé, 2021/10/30
- [PULL 04/30] hw/sh4: Coding style: Add missing braces, Philippe Mathieu-Daudé, 2021/10/30
- [PULL 05/30] hw/sh4: Coding style: Remove unnecessary casts, Philippe Mathieu-Daudé, 2021/10/30
- [PULL 06/30] hw/sh4: Fix typos in a comment, Philippe Mathieu-Daudé, 2021/10/30
- [PULL 07/30] hw/sh4: Change debug printfs to traces, Philippe Mathieu-Daudé, 2021/10/30
- [PULL 08/30] hw/sh4/r2d: Use error_report instead of fprintf to stderr, Philippe Mathieu-Daudé, 2021/10/30
- [PULL 09/30] hw/char/sh_serial: Do not abort on invalid access,
Philippe Mathieu-Daudé <=
- [PULL 10/30] hw/char/sh_serial: Rename type sh_serial_state to SHSerialState, Philippe Mathieu-Daudé, 2021/10/30
- [PULL 11/30] hw/char/sh_serial: Embed QEMUTimer in state struct, Philippe Mathieu-Daudé, 2021/10/30
- [PULL 12/30] hw/char/sh_serial: Split off sh_serial_reset() from sh_serial_init(), Philippe Mathieu-Daudé, 2021/10/30
- [PULL 13/30] hw/char/sh_serial: QOM-ify, Philippe Mathieu-Daudé, 2021/10/30
- [PULL 14/30] hw/char/sh_serial: Add device id to trace output, Philippe Mathieu-Daudé, 2021/10/30
- [PULL 15/30] hw/intc/sh_intc: Use existing macro instead of local one, Philippe Mathieu-Daudé, 2021/10/30
- [PULL 16/30] hw/intc/sh_intc: Turn some defines into an enum, Philippe Mathieu-Daudé, 2021/10/30
- [PULL 17/30] hw/intc/sh_intc: Rename iomem region, Philippe Mathieu-Daudé, 2021/10/30
- [PULL 18/30] hw/intc/sh_intc: Drop another useless macro, Philippe Mathieu-Daudé, 2021/10/30
- [PULL 19/30] hw/intc/sh_intc: Move sh_intc_register() closer to its only user, Philippe Mathieu-Daudé, 2021/10/30