qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Peter Crosthwaite <peter.crosthwaite@xilinx.com>
To: qemu-devel@nongnu.org
Cc: Peter Crosthwaite <peter.crosthwaite@xilinx.com>,
	andreas.faerber@suse.de, dantesu@faraday-tech.com
Subject: [Qemu-devel] [PATCH] sysbus: Guard against NULL SysBusDevice::init fn
Date: Sun,  3 Mar 2013 15:30:56 +1000	[thread overview]
Message-ID: <1362288656-29628-1-git-send-email-peter.crosthwaite@xilinx.com> (raw)

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 <peter.crosthwaite@xilinx.com>
---
 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,
-- 
1.7.0.4

             reply	other threads:[~2013-03-03  5:31 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-03  5:30 Peter Crosthwaite [this message]
2013-03-03 13:19 ` [Qemu-devel] [PATCH] sysbus: Guard against NULL SysBusDevice::init fn Andreas Färber
2013-03-03 13:27   ` Peter Maydell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1362288656-29628-1-git-send-email-peter.crosthwaite@xilinx.com \
    --to=peter.crosthwaite@xilinx.com \
    --cc=andreas.faerber@suse.de \
    --cc=dantesu@faraday-tech.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).