From patchwork Thu May 12 12:55:03 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Glauber Costa X-Patchwork-Id: 95301 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id A498BB6F6E for ; Thu, 12 May 2011 22:55:21 +1000 (EST) Received: from localhost ([::1]:54912 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QKVQD-0001yH-HZ for incoming@patchwork.ozlabs.org; Thu, 12 May 2011 08:55:17 -0400 Received: from eggs.gnu.org ([140.186.70.92]:47024) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QKVQ5-0001xR-Oo for qemu-devel@nongnu.org; Thu, 12 May 2011 08:55:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QKVQ5-00006z-0V for qemu-devel@nongnu.org; Thu, 12 May 2011 08:55:09 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56325) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QKVQ4-00006q-Ng for qemu-devel@nongnu.org; Thu, 12 May 2011 08:55:08 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p4CCt7dH002851 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 12 May 2011 08:55:07 -0400 Received: from mothafucka.localdomain (ovpn-113-97.phx2.redhat.com [10.3.113.97]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p4CCt4Ej025319; Thu, 12 May 2011 08:55:05 -0400 From: Glauber Costa To: kvm@vger.kernel.org Date: Thu, 12 May 2011 09:55:03 -0300 Message-Id: <1305204903-13283-1-git-send-email-glommer@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: aliguori@us.ibm.com, mtosatti@redhat.com, qemu-devel@nongnu.org, avi@redhat.com Subject: [Qemu-devel] [PATCH] Avoid segmentation fault for qdev device not found 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 qdev_try_create will cope well with a NULL bus, since it will assume the main system bus by default. qdev_create, however, wants to print a message, in which it instantiates the bus name. That simple and at first inoffensive message will generate a segmentation found if the reason for failure is a NULL bus. I propose we avoid that - thus generating the normal hw_error by always passing a valid bus to qdev_try_create - if none, be it the main system bus. The code for testing a NULL bus is not remove from qdev_try_create because it is a externally visible function, and we want it to continue working fine. Signed-off-by: Glauber Costa Reviewed-by: Markus Armbruster --- hw/qdev.c | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-) diff --git a/hw/qdev.c b/hw/qdev.c index 1aa1ea0..21ef075 100644 --- a/hw/qdev.c +++ b/hw/qdev.c @@ -108,6 +108,10 @@ DeviceState *qdev_create(BusState *bus, const char *name) { DeviceState *dev; + if (!bus) { + bus = sysbus_get_default(); + } + dev = qdev_try_create(bus, name); if (!dev) { hw_error("Unknown device '%s' for bus '%s'\n", name, bus->info->name);