From 9e36f6f56e78aaac640a24f7392a54770d71d969 Mon Sep 17 00:00:00 2001 From: Amit Shah Date: Wed, 28 Apr 2010 09:17:04 -0300 Subject: [PATCH 18/20] virtio-serial: Handle output from guest to unintialised ports RH-Author: Amit Shah Message-id: <1272446224-773-1-git-send-email-amit.shah@redhat.com> Patchwork-id: 8888 O-Subject: [RHEL6 PATCH v4.1 18/19] virtio-serial: Handle output from guest to unintialised ports Bugzilla: 574296 RH-Acked-by: Alon Levy RH-Acked-by: Gerd Hoffmann RH-Acked-by: Juan Quintela Guests can send data to ports that the host hasn't initialised. This used to be handled properly earlier but the code changed in the last series that made this condition expose a segfault. Fix that. (This patch depends on the previous series) Upstream: Bugzilla: 574296 Reported-by: Alon Levy Signed-off-by: Amit Shah --- hw/virtio-serial-bus.c | 18 +++++++++++++----- 1 files changed, 13 insertions(+), 5 deletions(-) Signed-off-by: Eduardo Habkost --- hw/virtio-serial-bus.c | 18 +++++++++++++----- 1 files changed, 13 insertions(+), 5 deletions(-) diff --git a/hw/virtio-serial-bus.c b/hw/virtio-serial-bus.c index de64154..3ce95e8 100644 --- a/hw/virtio-serial-bus.c +++ b/hw/virtio-serial-bus.c @@ -111,12 +111,13 @@ static size_t write_to_port(VirtIOSerialPort *port, return offset; } -static void flush_queued_data(VirtIOSerialPort *port, bool discard) +static void do_flush_queued_data(VirtIOSerialPort *port, VirtQueue *vq, + VirtIODevice *vdev, bool discard) { - VirtQueue *vq; VirtQueueElement elem; - vq = port->ovq; + assert(port || discard); + while ((discard || !port->throttled) && virtqueue_pop(vq, &elem)) { uint8_t *buf; size_t ret, buf_size; @@ -131,7 +132,14 @@ static void flush_queued_data(VirtIOSerialPort *port, bool discard) } virtqueue_push(vq, &elem, 0); } - virtio_notify(&port->vser->vdev, vq); + virtio_notify(vdev, vq); +} + +static void flush_queued_data(VirtIOSerialPort *port, bool discard) +{ + assert(port); + + do_flush_queued_data(port, port->ovq, &port->vser->vdev, discard); } static size_t send_control_msg(VirtIOSerialPort *port, void *buf, size_t len) @@ -404,7 +412,7 @@ static void handle_output(VirtIODevice *vdev, VirtQueue *vq) return; } - flush_queued_data(port, discard); + do_flush_queued_data(port, vq, vdev, discard); } static void handle_input(VirtIODevice *vdev, VirtQueue *vq) -- 1.7.0.3