From patchwork Tue Apr 16 01:50:21 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Andreas_F=C3=A4rber?= X-Patchwork-Id: 236819 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 5279F2C00F2 for ; Tue, 16 Apr 2013 11:51:03 +1000 (EST) Received: from localhost ([::1]:55981 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1URv2z-0006hf-Eu for incoming@patchwork.ozlabs.org; Mon, 15 Apr 2013 21:51:01 -0400 Received: from eggs.gnu.org ([208.118.235.92]:47977) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1URv2R-0006ha-Rz for qemu-devel@nongnu.org; Mon, 15 Apr 2013 21:50:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1URv2Q-0000lD-OD for qemu-devel@nongnu.org; Mon, 15 Apr 2013 21:50:27 -0400 Received: from cantor2.suse.de ([195.135.220.15]:59398 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1URv2Q-0000l8-Ho for qemu-devel@nongnu.org; Mon, 15 Apr 2013 21:50:26 -0400 Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id EDE0DA5694; Tue, 16 Apr 2013 03:50:24 +0200 (CEST) From: =?UTF-8?q?Andreas=20F=C3=A4rber?= To: qemu-devel@nongnu.org Date: Tue, 16 Apr 2013 03:50:21 +0200 Message-Id: <1366077021-28882-1-git-send-email-afaerber@suse.de> X-Mailer: git-send-email 1.8.1.4 MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x X-Received-From: 195.135.220.15 Cc: ehabkost@redhat.com, armbru@redhat.com, lcapitulino@redhat.com, anthony@codemonkey.ws, imammedo@redhat.com, pbonzini@redhat.com, =?UTF-8?q?Andreas=20F=C3=A4rber?= Subject: [Qemu-devel] [PATCH] qdev: Fix device_add bus assumptions 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 Drop an unreachable fallback bus assignment to SysBus. If no ,bus= is specified, only search busses recursively for bus type if the DeviceClass has a bus_type specified. Handle resulting NULL cases. Signed-off-by: Andreas Färber --- qdev-monitor.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/qdev-monitor.c b/qdev-monitor.c index 9a78ccf..73d7946 100644 --- a/qdev-monitor.c +++ b/qdev-monitor.c @@ -18,6 +18,7 @@ */ #include "hw/qdev.h" +#include "hw/sysbus.h" #include "monitor/monitor.h" #include "monitor/qdev.h" #include "qmp-commands.h" @@ -415,7 +416,7 @@ DeviceState *qdev_device_add(QemuOpts *opts) DeviceClass *k; const char *driver, *path, *id; DeviceState *qdev; - BusState *bus; + BusState *bus = NULL; driver = qemu_opt_get(opts, "driver"); if (!driver) { @@ -453,7 +454,7 @@ DeviceState *qdev_device_add(QemuOpts *opts) driver, object_get_typename(OBJECT(bus))); return NULL; } - } else { + } else if (k->bus_type != NULL) { bus = qbus_find_recursive(sysbus_get_default(), NULL, k->bus_type); if (!bus) { qerror_report(QERR_NO_BUS_FOR_DEVICE, @@ -461,18 +462,17 @@ DeviceState *qdev_device_add(QemuOpts *opts) return NULL; } } - if (qdev_hotplug && !bus->allow_hotplug) { + if (qdev_hotplug && bus && !bus->allow_hotplug) { qerror_report(QERR_BUS_NO_HOTPLUG, bus->name); return NULL; } - if (!bus) { - bus = sysbus_get_default(); - } - /* create device, set properties */ qdev = DEVICE(object_new(driver)); - qdev_set_parent_bus(qdev, bus); + + if (bus) { + qdev_set_parent_bus(qdev, bus); + } id = qemu_opts_id(opts); if (id) {