vl.c: Provide accessor function serial_hd() for serial_hds[] array
authorPeter Maydell <peter.maydell@linaro.org>
Fri, 20 Apr 2018 14:52:42 +0000 (15:52 +0100)
committerPeter Maydell <peter.maydell@linaro.org>
Thu, 26 Apr 2018 12:57:00 +0000 (13:57 +0100)
Provide an accessor function serial_hd() to return the Chardev
(if any) associated with the numbered serial port. This will
be used to replace direct accesses to the serial_hds[] array,
so that calling code doesn't need to care about the size of
that array.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Reviewed-by: Thomas Huth <thuth@redhat.com>
Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Message-id: 20180420145249.32435-7-peter.maydell@linaro.org

include/sysemu/sysemu.h
vl.c

index 2b42151c6300dcc851bd32d8a8c3e87735c884b9..bd5b55c514b958cf82f349f4e8a2affc690b40a6 100644 (file)
@@ -163,6 +163,9 @@ void hmp_pcie_aer_inject_error(Monitor *mon, const QDict *qdict);
 
 extern Chardev *serial_hds[MAX_SERIAL_PORTS];
 
+/* Return the Chardev for serial port i, or NULL if none */
+Chardev *serial_hd(int i);
+
 /* parallel ports */
 
 #define MAX_PARALLEL_PORTS 3
diff --git a/vl.c b/vl.c
index fce1fd12d8b73ad45d072b5dd47aee88b310a88a..6daf026da66f56877c39f03830adfa6349ca9b9a 100644 (file)
--- a/vl.c
+++ b/vl.c
@@ -2516,6 +2516,15 @@ static int serial_parse(const char *devname)
     return 0;
 }
 
+Chardev *serial_hd(int i)
+{
+    assert(i >= 0);
+    if (i < ARRAY_SIZE(serial_hds)) {
+        return serial_hds[i];
+    }
+    return NULL;
+}
+
 static int parallel_parse(const char *devname)
 {
     static int index = 0;