From patchwork Sun Mar 3 05:30:56 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Crosthwaite X-Patchwork-Id: 224531 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 15AF32C02FE for ; Sun, 3 Mar 2013 16:32:12 +1100 (EST) Received: from localhost ([::1]:36468 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UC1Ws-0000nK-36 for incoming@patchwork.ozlabs.org; Sun, 03 Mar 2013 00:32:10 -0500 Received: from eggs.gnu.org ([208.118.235.92]:47129) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UC1Wd-0000nF-3v for qemu-devel@nongnu.org; Sun, 03 Mar 2013 00:31:56 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UC1Wa-0007sx-BJ for qemu-devel@nongnu.org; Sun, 03 Mar 2013 00:31:55 -0500 Received: from mail-pb0-f44.google.com ([209.85.160.44]:55853) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UC1Wa-0007rq-4w for qemu-devel@nongnu.org; Sun, 03 Mar 2013 00:31:52 -0500 Received: by mail-pb0-f44.google.com with SMTP id wz12so2481238pbc.31 for ; Sat, 02 Mar 2013 21:31:51 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:sender:from:to:cc:subject:date:message-id:x-mailer :x-gm-message-state; bh=2eIFR3rI8ghTGxl9xVKsz799B+0Qb5O0EGXOFaL8v9g=; b=YEapDygozFTt5m68Ff64bMz1ZuIpYEHamsnLOjo/jPqFdrKblj2JPAJmyvlyB0Bkhx WxA4I9QkLtf1bnm3k6oT4HV6p0puSfNBVDXS7IlH6MaiMppvn0k+oWCD6UAc2vZnZpsr C3NwH34WgqOc8A/JguOVYpa5hyc0IiGabhptixnME+geRYAs8fm+FJrB8e9nldJz/IsQ VlEiBXrWb/OwBhv6op41LqaHAIwQIo4xWdKZNlGLBX4BKYvrEm1vzL1HWf9RgqYjSoJ0 jWG9d03xSD9lAX5ZpLRrOPUM0B3udh6GUCCg7FLOKhaxU6KKoJ9qWtpqYlHMTcFdKxtL bfhQ== X-Received: by 10.66.216.202 with SMTP id os10mr10857814pac.96.1362288710935; Sat, 02 Mar 2013 21:31:50 -0800 (PST) Received: from localhost ([149.199.62.254]) by mx.google.com with ESMTPS id g4sm19059547pax.4.2013.03.02.21.31.48 (version=TLSv1.1 cipher=RC4-SHA bits=128/128); Sat, 02 Mar 2013 21:31:50 -0800 (PST) From: Peter Crosthwaite To: qemu-devel@nongnu.org Date: Sun, 3 Mar 2013 15:30:56 +1000 Message-Id: <1362288656-29628-1-git-send-email-peter.crosthwaite@xilinx.com> X-Mailer: git-send-email 1.7.0.4 X-Gm-Message-State: ALoCoQkdpdAsP/nkXIVbscLzCeJaBHLDdqJ8xbdHsgb9aJTOVlNwwzdxc9BnWvGD08TWm9LFx4b8 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 209.85.160.44 Cc: Peter Crosthwaite , andreas.faerber@suse.de, dantesu@faraday-tech.com Subject: [Qemu-devel] [PATCH] sysbus: Guard against NULL SysBusDevice::init fn 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 In certain cases a device model can init with neither a Device::realize or SysBusDevice::init (i.e. when its possible to do everything in Object::init). In this case, the device model should be able to leave both SysBusDevice::init and Device::realize as NULL. However what happens in this case in SysBus's default Device::realize function will try and call SysBusDevice::init without checking if it actually exists. A segfault ensues. Fix by guarding the call to SysBusDevice::init against a NULL pointer. If no pointer is defined return 0 without action. Signed-off-by: Peter Crosthwaite --- hw/sysbus.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/hw/sysbus.c b/hw/sysbus.c index 6d9d1df..72b309a 100644 --- a/hw/sysbus.c +++ b/hw/sysbus.c @@ -118,7 +118,7 @@ static int sysbus_device_init(DeviceState *dev) SysBusDevice *sd = SYS_BUS_DEVICE(dev); SysBusDeviceClass *sbc = SYS_BUS_DEVICE_GET_CLASS(sd); - return sbc->init(sd); + return sbc->init ? sbc->init(sd) : 0; } DeviceState *sysbus_create_varargs(const char *name,