From patchwork Wed Aug 3 22:49:04 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 3252 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 5204823F3F for ; Wed, 3 Aug 2011 22:49:10 +0000 (UTC) Received: from mail-qw0-f52.google.com (mail-qw0-f52.google.com [209.85.216.52]) by fiordland.canonical.com (Postfix) with ESMTP id 1861FA1852A for ; Wed, 3 Aug 2011 22:49:10 +0000 (UTC) Received: by qwb8 with SMTP id 8so607599qwb.11 for ; Wed, 03 Aug 2011 15:49:09 -0700 (PDT) Received: by 10.229.183.84 with SMTP id cf20mr33635qcb.121.1312411749470; Wed, 03 Aug 2011 15:49:09 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.229.6.73 with SMTP id 9cs172317qcy; Wed, 3 Aug 2011 15:49:08 -0700 (PDT) Received: by 10.227.55.82 with SMTP id t18mr45173wbg.23.1312411747936; Wed, 03 Aug 2011 15:49:07 -0700 (PDT) Received: from mnementh.archaic.org.uk (mnementh.archaic.org.uk [81.2.115.146]) by mx.google.com with ESMTPS id fe3si2560803wbb.27.2011.08.03.15.49.06 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 03 Aug 2011 15:49:06 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 81.2.115.146 as permitted sender) client-ip=81.2.115.146; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 81.2.115.146 as permitted sender) smtp.mail=pm215@archaic.org.uk Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.72) (envelope-from ) id 1QokFM-0002QJ-5t; Wed, 03 Aug 2011 23:49:04 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org, qemu-trivial@nongnu.org Subject: [PATCH] hw/qdev: Don't crash if qdev_create(NULL, ...) fails Date: Wed, 3 Aug 2011 23:49:04 +0100 Message-Id: <1312411744-9292-1-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.2.5 If an attempt to create a qdev device on the default sysbus (by passing NULL as the bus to qdev_create) fails, print a useful error message rather than crashing trying to dereference a NULL pointer. Signed-off-by: Peter Maydell Reviewed-by: Markus Armbruster --- hw/qdev.c | 7 ++++++- 1 files changed, 6 insertions(+), 1 deletions(-) diff --git a/hw/qdev.c b/hw/qdev.c index b4ea8e1..3fec62a 100644 --- a/hw/qdev.c +++ b/hw/qdev.c @@ -110,7 +110,12 @@ DeviceState *qdev_create(BusState *bus, const char *name) dev = qdev_try_create(bus, name); if (!dev) { - hw_error("Unknown device '%s' for bus '%s'\n", name, bus->info->name); + if (bus) { + hw_error("Unknown device '%s' for bus '%s'\n", name, + bus->info->name); + } else { + hw_error("Unknown device '%s' for default sysbus\n", name); + } } return dev;