From: Amit Shah <amit.shah@redhat.com>
To: qemu list <qemu-devel@nongnu.org>
Cc: Amit Shah <amit.shah@redhat.com>, Amos Kong <akong@redhat.com>,
Markus Armbruster <armbru@redhat.com>
Subject: [Qemu-devel] [PATCH 2/2] virtio-serial: search for duplicate port names before adding new ports
Date: Wed, 16 Jul 2014 17:01:04 +0530 [thread overview]
Message-ID: <62534c199055120cb0b38738759fa69943951632.1405510095.git.amit.shah@redhat.com> (raw)
In-Reply-To: <cover.1405510095.git.amit.shah@redhat.com>
In-Reply-To: <cover.1405510095.git.amit.shah@redhat.com>
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: <mazhang@redhat.com>
Signed-off-by: Amit Shah <amit.shah@redhat.com>
---
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
next prev parent reply other threads:[~2014-07-16 11:32 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-16 11:31 [Qemu-devel] [PATCH 0/2] virtio-serial: Prevent addition of ports with same name Amit Shah
2014-07-16 11:31 ` [Qemu-devel] [PATCH 1/2] virtio-serial: create a linked list of all active devices Amit Shah
2014-08-04 11:33 ` Markus Armbruster
2014-08-04 11:45 ` Amit Shah
2014-08-06 7:27 ` Markus Armbruster
2014-08-06 7:39 ` Amit Shah
2014-08-18 17:21 ` Andreas Färber
2014-08-19 15:45 ` Markus Armbruster
2014-08-19 16:15 ` Andreas Färber
2014-07-16 11:31 ` Amit Shah [this message]
2014-08-06 7:27 ` [Qemu-devel] [PATCH 0/2] virtio-serial: Prevent addition of ports with same name Markus Armbruster
2014-08-06 7:39 ` Amit Shah
2014-08-18 17:10 ` Amit Shah
2014-08-18 17:17 ` Andreas Färber
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=62534c199055120cb0b38738759fa69943951632.1405510095.git.amit.shah@redhat.com \
--to=amit.shah@redhat.com \
--cc=akong@redhat.com \
--cc=armbru@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).