From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38934) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X7NRH-0005iI-Da for qemu-devel@nongnu.org; Wed, 16 Jul 2014 07:32:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1X7NR9-0005Wz-VG for qemu-devel@nongnu.org; Wed, 16 Jul 2014 07:31:59 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56910) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X7NR9-0005Wr-MD for qemu-devel@nongnu.org; Wed, 16 Jul 2014 07:31:51 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s6GBVpOK027262 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Wed, 16 Jul 2014 07:31:51 -0400 From: Amit Shah Date: Wed, 16 Jul 2014 17:01:04 +0530 Message-Id: <62534c199055120cb0b38738759fa69943951632.1405510095.git.amit.shah@redhat.com> In-Reply-To: References: In-Reply-To: References: Subject: [Qemu-devel] [PATCH 2/2] virtio-serial: search for duplicate port names before adding new ports List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu list Cc: Amit Shah , Amos Kong , Markus Armbruster Before adding new ports to VirtIOSerial devices, check if there's a conflict in the 'name' parameter. This ensures two virtserialports with identical names are not initialized. Reported-by: Signed-off-by: Amit Shah --- hw/char/virtio-serial-bus.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/hw/char/virtio-serial-bus.c b/hw/char/virtio-serial-bus.c index 8c26f4e..76e4228 100644 --- a/hw/char/virtio-serial-bus.c +++ b/hw/char/virtio-serial-bus.c @@ -56,6 +56,22 @@ static VirtIOSerialPort *find_port_by_vq(VirtIOSerial *vser, VirtQueue *vq) return NULL; } +static VirtIOSerialPort *find_port_by_name(char *name) +{ + VirtIOSerial *vser; + + QLIST_FOREACH(vser, &vserdevices.devices, next) { + VirtIOSerialPort *port; + + QTAILQ_FOREACH(port, &vser->ports, next) { + if (!strcmp(port->name, name)) { + return port; + } + } + } + return NULL; +} + static bool use_multiport(VirtIOSerial *vser) { VirtIODevice *vdev = VIRTIO_DEVICE(vser); @@ -847,6 +863,12 @@ static void virtser_port_device_realize(DeviceState *dev, Error **errp) return; } + if (find_port_by_name(port->name)) { + error_setg(errp, "virtio-serial-bus: A port already exists by name %s", + port->name); + return; + } + if (port->id == VIRTIO_CONSOLE_BAD_ID) { if (plugging_port0) { port->id = 0; -- 1.9.3