All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 1/3] virtio-console: Check if chardev backends available before calling into them
@ 2011-12-21  6:58 Amit Shah
  2011-12-21  6:58 ` [Qemu-devel] [PATCH 2/3] virtio-console: Properly initialise class methods Amit Shah
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Amit Shah @ 2011-12-21  6:58 UTC (permalink / raw)
  To: Anthony Liguori; +Cc: Amit Shah, Paolo Bonzini, qemu list, Markus Armbruster

For the callback functions invoked by the virtio-serial-bus code, check
if we have chardev backends registered before we call into the chardev
functions.

Signed-off-by: Amit Shah <amit.shah@redhat.com>
---
 hw/virtio-console.c |   11 +++++++++++
 1 files changed, 11 insertions(+), 0 deletions(-)

diff --git a/hw/virtio-console.c b/hw/virtio-console.c
index d3351c8..dbbea76 100644
--- a/hw/virtio-console.c
+++ b/hw/virtio-console.c
@@ -27,6 +27,11 @@ static ssize_t flush_buf(VirtIOSerialPort *port, const uint8_t *buf, size_t len)
     VirtConsole *vcon = DO_UPCAST(VirtConsole, port, port);
     ssize_t ret;
 
+    if (!vcon->chr) {
+        /* If there's no backend, we can just say we consumed all data. */
+        return len;
+    }
+
     ret = qemu_chr_fe_write(vcon->chr, buf, len);
     trace_virtio_console_flush_buf(port->id, len, ret);
 
@@ -52,6 +57,9 @@ static void guest_open(VirtIOSerialPort *port)
 {
     VirtConsole *vcon = DO_UPCAST(VirtConsole, port, port);
 
+    if (!vcon->chr) {
+        return;
+    }
     qemu_chr_fe_open(vcon->chr);
 }
 
@@ -60,6 +68,9 @@ static void guest_close(VirtIOSerialPort *port)
 {
     VirtConsole *vcon = DO_UPCAST(VirtConsole, port, port);
 
+    if (!vcon->chr) {
+        return;
+    }
     qemu_chr_fe_close(vcon->chr);
 }
 
-- 
1.7.7.4

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2011-12-21 22:05 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-12-21  6:58 [Qemu-devel] [PATCH 1/3] virtio-console: Check if chardev backends available before calling into them Amit Shah
2011-12-21  6:58 ` [Qemu-devel] [PATCH 2/3] virtio-console: Properly initialise class methods Amit Shah
2011-12-21  6:58 ` [Qemu-devel] [PATCH 3/3] virtio-serial-bus: Ports are expected to implement 'have_data' callback Amit Shah
2011-12-21 22:05 ` [Qemu-devel] [PATCH 1/3] virtio-console: Check if chardev backends available before calling into them Anthony Liguori

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.