mirror of
https://github.com/xemu-project/xemu.git
synced 2025-02-17 10:38:52 +00:00
virtio-serial: search for duplicate port names before adding new ports
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> Reviewed-by: Markus Armbruster <armbru@redhat.com>
This commit is contained in:
parent
a1857ad1ac
commit
d0a0bfe672
@ -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);
|
||||
@ -855,6 +871,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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user