Skip to contentSkip to conversation

hw/char/serial: Fix crash when serial_mm_init() is used with -nodefaults

PATCH New Thomas Huth 1 participant 1 message Mar 19, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hw/char/serial: Fix crash when serial_mm_init() is used with -nodefaults

Quite a lot of boards call serial_mm_init() directly with a value from the serial_hds[] table. However, this table is only containing NULL if QEMU has been started with "-nodefaults":

$ gdb --args arm-softmmu/qemu-system-arm -S -nodefaults -M cubieboard
(gdb) r
Program received signal SIGSEGV, Segmentation fault.
qemu_chr_fe_init (b=b@entry=0x555556cc4260, s=s@entry=0x0, errp=0x55555697eb40 <error_abort>)
    at chardev/char-fe.c:210
210	    } else if (s->be) {

Since calling serial_mm_init with a NULL pointer seems to be a common pattern between many boards, let's simply fix this by creating a "null" chardev on the fly in this case.

---
 hw/char/serial.c | 4 ++++
 1 file changed, 4 insertions(+)
hw/char/serial.c +4 -0
index eb72191..c1f7ff7 100644
@@ -1040,6 +1040,10 @@ SerialState *serial_mm_init(MemoryRegion *address_space,
 {
     SerialState *s;
 
+    if (!chr) {
+        chr = qemu_chardev_new(NULL, TYPE_CHARDEV_NULL, NULL, &error_abort);
+    }
+
     s = g_malloc0(sizeof(SerialState));
 
     s->it_shift = it_shift;
Signature · 1 line
1.8.3.1