From patchwork Fri Apr 20 14:52:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 901975 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=linaro.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40SJvB0Vm5z9s1t for ; Sat, 21 Apr 2018 01:00:38 +1000 (AEST) Received: from localhost ([::1]:35247 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f9XWd-0004Dy-4d for incoming@patchwork.ozlabs.org; Fri, 20 Apr 2018 11:00:35 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43419) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f9XPR-0006Pu-VP for qemu-devel@nongnu.org; Fri, 20 Apr 2018 10:53:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f9XPR-0007tK-86 for qemu-devel@nongnu.org; Fri, 20 Apr 2018 10:53:10 -0400 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:40996) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1f9XPR-0007mN-1T for qemu-devel@nongnu.org; Fri, 20 Apr 2018 10:53:09 -0400 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.89) (envelope-from ) id 1f9XPC-0006Yj-Gy; Fri, 20 Apr 2018 15:52:54 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Date: Fri, 20 Apr 2018 15:52:42 +0100 Message-Id: <20180420145249.32435-7-peter.maydell@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180420145249.32435-1-peter.maydell@linaro.org> References: <20180420145249.32435-1-peter.maydell@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2001:8b0:1d0::2 Subject: [Qemu-devel] [PATCH 06/13] vl.c: Provide accessor function serial_hd() for serial_hds[] array X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , "Michael S . Tsirkin" , =?utf-8?q?Philippe_Mathieu-Da?= =?utf-8?q?ud=C3=A9?= , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , patches@linaro.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 Reviewed-by: Philippe Mathieu-Daudé Tested-by: Philippe Mathieu-Daudé Reviewed-by: Thomas Huth --- include/sysemu/sysemu.h | 3 +++ vl.c | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h index 2b42151c63..bd5b55c514 100644 --- a/include/sysemu/sysemu.h +++ b/include/sysemu/sysemu.h @@ -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 fce1fd12d8..6daf026da6 100644 --- 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;