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: 779802 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p4CCtNoM017721 for ; Thu, 12 May 2011 12:55:23 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754911Ab1ELMzU (ORCPT ); Thu, 12 May 2011 08:55:20 -0400 Received: from mx1.redhat.com ([209.132.183.28]:23425 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754655Ab1ELMzT (ORCPT ); Thu, 12 May 2011 08:55:19 -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 Cc: qemu-devel@nongnu.org, avi@redhat.com, aliguori@us.ibm.com, mtosatti@redhat.com Subject: [PATCH] Avoid segmentation fault for qdev device not found 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 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Thu, 12 May 2011 12:55:23 +0000 (UTC) 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);