Skip to content

Commit

Permalink
qdev: Avoid type assertion in qdev_build_hotpluggable_device_list()
Browse files Browse the repository at this point in the history
Currently when *obj is not a TYPE_DEVICE, QEMU will abort. This patch
fixes it. When *obj is not a TYPE_DEVICE, just do not add it to hotpluggable
device list.

This patch also fixes the following issue:
1. boot QEMU using cli:
$ /opt/qemu-git-arm/bin/qemu-system-x86_64 -monitor stdio -enable-kvm \
-device virtio-scsi-pci,id=scsi0

2. device_del scsi0 via hmp using tab key(first input device_del, then press
"Tab" key).
(qemu) device_del

After step 2, QEMU will abort.
(qemu) device_del hw/core/qdev.c:930:qdev_build_hotpluggable_device_list:
Object 0x5555563a2460 is not an instance of type device

Signed-off-by: Jun Li <junmuzi@gmail.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Cc: qemu-stable@nongnu.org
Signed-off-by: Andreas Färber <afaerber@suse.de>
(cherry picked from commit 09d5601)
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
  • Loading branch information
junmuzi authored and mdroth committed Mar 9, 2015
1 parent 3e04f97 commit 4ec1b9b
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion hw/core/qdev.c
Expand Up @@ -938,7 +938,12 @@ void qdev_alias_all_properties(DeviceState *target, Object *source)
static int qdev_add_hotpluggable_device(Object *obj, void *opaque)
{
GSList **list = opaque;
DeviceState *dev = DEVICE(obj);
DeviceState *dev = (DeviceState *)object_dynamic_cast(OBJECT(obj),
TYPE_DEVICE);

if (dev == NULL) {
return 0;
}

if (dev->realized && object_property_get_bool(obj, "hotpluggable", NULL)) {
*list = g_slist_append(*list, dev);
Expand Down

0 comments on commit 4ec1b9b

Please sign in to comment.