Commit 12051d82 authored by Peter Maydell's avatar Peter Maydell Committed by Paolo Bonzini
Browse files

chardev/char-fe: Allow NULL chardev in qemu_chr_fe_init()



All the functions in char-fe.c handle the CharBackend
having a NULL Chardev pointer, which means that the
backend exists but is not connected to anything. The
exception is qemu_chr_fe_init(), which will crash if
passed a NULL Chardev pointer argument. This can happen
for various boards if they're started with 'nodefaults':
 arm-softmmu/qemu-system-arm -S -nodefaults -M cubieboard
 riscv32-softmmu/qemu-system-riscv32 -nodefaults -M sifive_e

Make qemu_chr_fe_init() accept a NULL chardev. This allows
UART models to handle NULL chardev properties without
generally needing to special case them or to manually
create a NullChardev.

Reported-by: default avatarThomas Huth <thuth@redhat.com>
Signed-off-by: default avatarPeter Maydell <peter.maydell@linaro.org>
Message-Id: <20180323152948.27048-1-peter.maydell@linaro.org>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent 90c558be
Loading
Loading
Loading
Loading
+12 −10
Original line number Diff line number Diff line
@@ -198,6 +198,7 @@ bool qemu_chr_fe_init(CharBackend *b, Chardev *s, Error **errp)
{
    int tag = 0;

    if (s) {
        if (CHARDEV_IS_MUX(s)) {
            MuxChardev *d = MUX_CHARDEV(s);

@@ -212,6 +213,7 @@ bool qemu_chr_fe_init(CharBackend *b, Chardev *s, Error **errp)
        } else {
            s->be = b;
        }
    }

    b->fe_open = false;
    b->tag = tag;