From patchwork Wed Nov 5 07:03:03 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: lijun X-Patchwork-Id: 406881 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.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 1D1B514008C for ; Wed, 5 Nov 2014 18:03:53 +1100 (AEDT) Received: from localhost ([::1]:44607 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XludC-0006yo-TN for incoming@patchwork.ozlabs.org; Wed, 05 Nov 2014 02:03:50 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51764) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xlucl-0006h4-4A for qemu-devel@nongnu.org; Wed, 05 Nov 2014 02:03:32 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Xlucc-0005hg-2o for qemu-devel@nongnu.org; Wed, 05 Nov 2014 02:03:23 -0500 Received: from mail-pa0-x22f.google.com ([2607:f8b0:400e:c03::22f]:59768) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xlucb-0005gV-Ry for qemu-devel@nongnu.org; Wed, 05 Nov 2014 02:03:14 -0500 Received: by mail-pa0-f47.google.com with SMTP id kx10so200771pab.6 for ; Tue, 04 Nov 2014 23:03:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=x/JYHj+pTAyu/IGDnTKPLh8hpnCPhOui1jicUQU+Exs=; b=eO7OdberOVmQ5l9mJqMzovhjEYYOl78TRzBST5CpUwtmcSRVB54547aoWtOPZOEuUe A7Hhe5MlSRs+Sx/OttwsSDK6zXsBWkPm5ROed9GZ4g0dQgLQLN3WRYzL0LOWfN/Ph5d6 DOp8/0x8WM9pT0gmA4vEULIVgvffsg31kopfwg8JW5zsAk9RHCWYmUnmZKQ8akm2YUpc Aakg1YYWDntw4OeDDIw4/AGSe8LI1wArOK4cmT6g5higgk9vIVmDpt1on8WoxQYC8EFD u4fhLiN3Fu923tpAbHzIXe9AeYcmVuDM22rqZhxDIO5p6HQOv7p+tig6w8TpYz7XQOs+ kSPA== X-Received: by 10.70.96.36 with SMTP id dp4mr15793884pdb.116.1415170992267; Tue, 04 Nov 2014 23:03:12 -0800 (PST) Received: from localhost ([203.114.244.88]) by mx.google.com with ESMTPSA id 16sm2213970pdj.42.2014.11.04.23.03.10 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 04 Nov 2014 23:03:11 -0800 (PST) From: Jun Li To: qemu-devel@nongnu.org Date: Wed, 5 Nov 2014 15:03:03 +0800 Message-Id: <1415170983-12981-1-git-send-email-junmuzi@gmail.com> X-Mailer: git-send-email 1.9.3 X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:400e:c03::22f Cc: peter.crosthwaite@xilinx.com, famz@redhat.com, mst@redhat.com, juli@redhat.com, imammedo@redhat.com, pbonzini@redhat.com, Jun Li , afaerber@suse.de Subject: [Qemu-devel] [PATCH v3] qdev: Avoid type assertion in qdev_build_hotpluggable_device_list() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Currently when *obj is not a TYPE_DEVICE, qemu will abort. This patch just fixed it. When *obj is not a TYPE_DEVICE, just do not add it to hotpluggable device list. This patch also fixed 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 step2, 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 Reviewed-by: Paolo Bonzini --- v3: According to Andreas's suggestion, do some changes. As followings: 1, change the Subject to more meaningful. 2, use two "return 0" to return early avoid reindentation. And I have found in qcow2_grow_l1_table has also used two "return 0". So accept Andreas's suggestion. Thanks. v2: This version just do a little changes for the commit message. As following show: In v1, 1, boot qemu using cli: virtio-scsi-pci,id=scsi0 -enable-kvm In v2, 1, boot qemu using cli: $ /opt/qemu-git-arm/bin/qemu-system-x86_64 -monitor stdio -enable-kvm \ -device virtio-scsi-pci,id=scsi0 --- hw/core/qdev.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/hw/core/qdev.c b/hw/core/qdev.c index b3d5196..7db3e13 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -927,7 +927,12 @@ void qdev_alias_all_properties(DeviceState *target, Object *source) int qdev_build_hotpluggable_device_list(Object *obj, void *opaque) { GSList **list = opaque; - DeviceState *dev = DEVICE(obj); + DeviceState *dev = (DeviceState *)object_dynamic_cast(OBJECT(obj), + "device"); + + if (dev == NULL) { + return 0; + } if (dev->realized && object_property_get_bool(obj, "hotpluggable", NULL)) { *list = g_slist_append(*list, dev);