[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 050/113] hw/char/serial: Clean up unnecessary code
From: |
Paolo Bonzini |
Subject: |
[PULL 050/113] hw/char/serial: Clean up unnecessary code |
Date: |
Wed, 2 Dec 2020 03:07:46 -0500 |
From: Philippe Mathieu-Daudé <f4bug@amsat.org>
Since commit 5ec3a23e6c8 ("serial: convert PIO to new memory
api read/write") we don't need to worry about accesses bigger
than 8-bit. Use the extract()/deposit() functions to access
the correct part of the 16-bit 'divider' register.
Reported-by: Jonathan D. Belanger <jbelanger1@rochester.rr.com>
Buglink: https://bugs.launchpad.net/qemu/+bug/1904331
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Message-Id: <20201120161933.2514089-1-f4bug@amsat.org>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
hw/char/serial.c | 13 +++++--------
1 file changed, 5 insertions(+), 8 deletions(-)
diff --git a/hw/char/serial.c b/hw/char/serial.c
index 97f71879ff..62c627f486 100644
--- a/hw/char/serial.c
+++ b/hw/char/serial.c
@@ -24,6 +24,7 @@
*/
#include "qemu/osdep.h"
+#include "qemu/bitops.h"
#include "hw/char/serial.h"
#include "hw/irq.h"
#include "migration/vmstate.h"
@@ -338,11 +339,7 @@ static void serial_ioport_write(void *opaque, hwaddr addr,
uint64_t val,
default:
case 0:
if (s->lcr & UART_LCR_DLAB) {
- if (size == 1) {
- s->divider = (s->divider & 0xff00) | val;
- } else {
- s->divider = val;
- }
+ s->divider = deposit32(s->divider, 8 * addr, 8, val);
serial_update_parameters(s);
} else {
s->thr = (uint8_t) val;
@@ -364,7 +361,7 @@ static void serial_ioport_write(void *opaque, hwaddr addr,
uint64_t val,
break;
case 1:
if (s->lcr & UART_LCR_DLAB) {
- s->divider = (s->divider & 0x00ff) | (val << 8);
+ s->divider = deposit32(s->divider, 8 * addr, 8, val);
serial_update_parameters(s);
} else {
uint8_t changed = (s->ier ^ val) & 0x0f;
@@ -478,7 +475,7 @@ static uint64_t serial_ioport_read(void *opaque, hwaddr
addr, unsigned size)
default:
case 0:
if (s->lcr & UART_LCR_DLAB) {
- ret = s->divider & 0xff;
+ ret = extract16(s->divider, 8 * addr, 8);
} else {
if(s->fcr & UART_FCR_FE) {
ret = fifo8_is_empty(&s->recv_fifo) ?
@@ -502,7 +499,7 @@ static uint64_t serial_ioport_read(void *opaque, hwaddr
addr, unsigned size)
break;
case 1:
if (s->lcr & UART_LCR_DLAB) {
- ret = (s->divider >> 8) & 0xff;
+ ret = extract16(s->divider, 8 * addr, 8);
} else {
ret = s->ier;
}
--
2.26.2
- [PULL 052/113] vl: extract validation of -smp to machine.c, (continued)
- [PULL 052/113] vl: extract validation of -smp to machine.c, Paolo Bonzini, 2020/12/02
- [PULL 063/113] vl: load plugins as late as possible, Paolo Bonzini, 2020/12/02
- [PULL 054/113] vl: split various early command line options to a separate function, Paolo Bonzini, 2020/12/02
- [PULL 058/113] vl: extract various command line validation snippets to a new function, Paolo Bonzini, 2020/12/02
- [PULL 039/113] i386: do not use ram_size global, Paolo Bonzini, 2020/12/02
- [PULL 047/113] s390x: do not use ram_size global, Paolo Bonzini, 2020/12/02
- [PULL 055/113] vl: move various initialization routines out of qemu_init, Paolo Bonzini, 2020/12/02
- [PULL 062/113] vl: create "-net nic -net user" default earlier, Paolo Bonzini, 2020/12/02
- [PULL 057/113] vl: move prelaunch part of qemu_init to new functions, Paolo Bonzini, 2020/12/02
- [PULL 059/113] vl: preconfig and loadvm are mutually exclusive, Paolo Bonzini, 2020/12/02
- [PULL 050/113] hw/char/serial: Clean up unnecessary code,
Paolo Bonzini <=
- [PULL 064/113] vl: extract default devices to separate functions, Paolo Bonzini, 2020/12/02
- [PULL 071/113] vl: initialize displays before preconfig loop, Paolo Bonzini, 2020/12/02
- [PULL 070/113] vl: separate qemu_resolve_machine_memdev, Paolo Bonzini, 2020/12/02
- [PULL 066/113] vl: separate qemu_create_early_backends, Paolo Bonzini, 2020/12/02
- [PULL 076/113] vl: extract softmmu/datadir.c, Paolo Bonzini, 2020/12/02
- [PULL 080/113] vl: clean up -boot variables, Paolo Bonzini, 2020/12/02
- [PULL 074/113] vl: start VM via qmp_cont, Paolo Bonzini, 2020/12/02
- [PULL 084/113] kernel-doc: add support for ____cacheline_aligned_in_smp attribute, Paolo Bonzini, 2020/12/02
- [PULL 086/113] scripts: kernel-doc: proper handle @foo->bar(), Paolo Bonzini, 2020/12/02
- [PULL 088/113] scripts: kernel-doc: accept blank lines on parameter description, Paolo Bonzini, 2020/12/02