From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:57544) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UC8pn-0003Nh-Dd for qemu-devel@nongnu.org; Sun, 03 Mar 2013 08:20:13 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UC8pm-0003hE-7r for qemu-devel@nongnu.org; Sun, 03 Mar 2013 08:20:11 -0500 Received: from cantor2.suse.de ([195.135.220.15]:56952 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UC8pm-00035J-1H for qemu-devel@nongnu.org; Sun, 03 Mar 2013 08:20:10 -0500 Message-ID: <51334DDA.70903@suse.de> Date: Sun, 03 Mar 2013 14:19:22 +0100 From: =?ISO-8859-1?Q?Andreas_F=E4rber?= MIME-Version: 1.0 References: <1362288656-29628-1-git-send-email-peter.crosthwaite@xilinx.com> In-Reply-To: <1362288656-29628-1-git-send-email-peter.crosthwaite@xilinx.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH] sysbus: Guard against NULL SysBusDevice::init fn List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Crosthwaite Cc: Peter Maydell , qemu-devel@nongnu.org, dantesu@faraday-tech.com Am 03.03.2013 06:30, schrieb Peter Crosthwaite: > 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 SysBusDevic= e::init > and Device::realize as NULL. However what happens in this case in SysBu= s's > default Device::realize function will try and call SysBusDevice::init w= ithout > checking if it actually exists. A segfault ensues. >=20 > Fix by guarding the call to SysBusDevice::init against a NULL pointer. = If no > pointer is defined return 0 without action. >=20 > Signed-off-by: Peter Crosthwaite While the patch is correct, I believe PMM already posted one using an extra if two weeks ago as part of some series... Andreas > --- > hw/sysbus.c | 2 +- > 1 files changed, 1 insertions(+), 1 deletions(-) >=20 > 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 =3D SYS_BUS_DEVICE(dev); > SysBusDeviceClass *sbc =3D SYS_BUS_DEVICE_GET_CLASS(sd); > =20 > - return sbc->init(sd); > + return sbc->init ? sbc->init(sd) : 0; > } > =20 > DeviceState *sysbus_create_varargs(const char *name, >=20 --=20 SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 N=FCrnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imend=F6rffer; HRB 16746 AG N=FCrnbe= rg