[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 21/57] hw/char/serial: Assert serial_ioport_read/write offset fits
From: |
Paolo Bonzini |
Subject: |
[PULL 21/57] hw/char/serial: Assert serial_ioport_read/write offset fits 8 bytes |
Date: |
Sat, 19 Sep 2020 11:58:40 -0400 |
From: Philippe Mathieu-Daudé <f4bug@amsat.org>
The serial device has 8 registers, each 8-bit. The MemoryRegionOps
'serial_io_ops' is initialized with max_access_size=1, and all
memory_region_init_io() callers correctly set the region size to
8 bytes:
- serial_io_realize
- serial_isa_realizefn
- serial_pci_realize
- multi_serial_pci_realize
It is safe to assert the offset argument of serial_ioport_read()
and serial_ioport_write() is always less than 8.
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20200907015535.827885-2-f4bug@amsat.org>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
hw/char/serial.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/hw/char/serial.c b/hw/char/serial.c
index fd80ae5592..840da89de7 100644
--- a/hw/char/serial.c
+++ b/hw/char/serial.c
@@ -344,7 +344,7 @@ static void serial_ioport_write(void *opaque, hwaddr addr,
uint64_t val,
{
SerialState *s = opaque;
- addr &= 7;
+ assert(size == 1 && addr < 8);
trace_serial_ioport_write(addr, val);
switch(addr) {
default:
@@ -485,7 +485,7 @@ static uint64_t serial_ioport_read(void *opaque, hwaddr
addr, unsigned size)
SerialState *s = opaque;
uint32_t ret;
- addr &= 7;
+ assert(size == 1 && addr < 8);
switch(addr) {
default:
case 0:
--
2.26.2
- [PULL 24/57] hw/char/serial: Rename I/O read/write trace events, (continued)
- [PULL 24/57] hw/char/serial: Rename I/O read/write trace events, Paolo Bonzini, 2020/09/19
- [PULL 28/57] hw: megasas: return -1 when 'megasas_map_sgl' fails, Paolo Bonzini, 2020/09/19
- [PULL 19/57] hw/char/serial: Remove TYPE_SERIAL_IO, Paolo Bonzini, 2020/09/19
- [PULL 14/57] acpi: i386: Move VMBus DSDT entry to SB, Paolo Bonzini, 2020/09/19
- [PULL 13/57] Simplify the .gitignore file, Paolo Bonzini, 2020/09/19
- [PULL 15/57] numa: drop support for '-numa node' (without memory specified), Paolo Bonzini, 2020/09/19
- [PULL 26/57] hw/char/serial-{isa, pci}: Alias QDEV properties from generic serial object, Paolo Bonzini, 2020/09/19
- [PULL 29/57] hw: megasas: consider 'iov_count=0' is an error in megasas_map_sgl, Paolo Bonzini, 2020/09/19
- [PULL 31/57] meson: move libudev test, Paolo Bonzini, 2020/09/19
- [PULL 45/57] oslib-posix: relocate path to /var, Paolo Bonzini, 2020/09/19
- [PULL 21/57] hw/char/serial: Assert serial_ioport_read/write offset fits 8 bytes,
Paolo Bonzini <=
- [PULL 32/57] meson: move libmpathpersist test, Paolo Bonzini, 2020/09/19
- [PULL 47/57] net: relocate paths to helpers and scripts, Paolo Bonzini, 2020/09/19
- [PULL 35/57] configure: fix --meson=/path/to/meson, Paolo Bonzini, 2020/09/19
- [PULL 52/57] ui: relocate paths to icons and translations, Paolo Bonzini, 2020/09/19
- [PULL 18/57] hw/mips/mipssim: Use MMIO serial device on fake ISA I/O, Paolo Bonzini, 2020/09/19
- [PULL 40/57] meson: report accelerator support, Paolo Bonzini, 2020/09/19
- [PULL 53/57] configure: use a platform-neutral prefix, Paolo Bonzini, 2020/09/19
- [PULL 20/57] configure: rename QEMU_GA_MSI_ENABLED to CONFIG_QGA_MSI, Paolo Bonzini, 2020/09/19
- [PULL 22/57] hw/char/serial: Replace commented DPRINTF() by trace event, Paolo Bonzini, 2020/09/19
- [PULL 25/57] hw/char/serial: Make 'wakeup' property boolean, Paolo Bonzini, 2020/09/19