* [Qemu-devel] [PATCH] sysbus: Guard against NULL SysBusDevice::init fn
@ 2013-03-03 5:30 Peter Crosthwaite
2013-03-03 13:19 ` Andreas Färber
0 siblings, 1 reply; 3+ messages in thread
From: Peter Crosthwaite @ 2013-03-03 5:30 UTC (permalink / raw)
To: qemu-devel; +Cc: Peter Crosthwaite, andreas.faerber, dantesu
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
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [PATCH] sysbus: Guard against NULL SysBusDevice::init fn
2013-03-03 5:30 [Qemu-devel] [PATCH] sysbus: Guard against NULL SysBusDevice::init fn Peter Crosthwaite
@ 2013-03-03 13:19 ` Andreas Färber
2013-03-03 13:27 ` Peter Maydell
0 siblings, 1 reply; 3+ messages in thread
From: Andreas Färber @ 2013-03-03 13:19 UTC (permalink / raw)
To: Peter Crosthwaite; +Cc: Peter Maydell, qemu-devel, dantesu
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 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>
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(-)
>
> 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,
>
--
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [PATCH] sysbus: Guard against NULL SysBusDevice::init fn
2013-03-03 13:19 ` Andreas Färber
@ 2013-03-03 13:27 ` Peter Maydell
0 siblings, 0 replies; 3+ messages in thread
From: Peter Maydell @ 2013-03-03 13:27 UTC (permalink / raw)
To: Andreas Färber; +Cc: Peter Crosthwaite, qemu-devel, dantesu
On 3 March 2013 21:19, Andreas Färber <afaerber@suse.de> wrote:
> Am 03.03.2013 06:30, schrieb Peter Crosthwaite:
>> 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>
>
> While the patch is correct, I believe PMM already posted one using an
> extra if two weeks ago as part of some series...
Yep, http://patchwork.ozlabs.org/patch/222985/
-- PMM
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2013-03-03 13:28 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-03-03 5:30 [Qemu-devel] [PATCH] sysbus: Guard against NULL SysBusDevice::init fn Peter Crosthwaite
2013-03-03 13:19 ` Andreas Färber
2013-03-03 13:27 ` Peter Maydell
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).