Patchwork [v2,1/5] sysbus: make SysBusDeviceClass::init optional

login
register
mail settings
Submitter Peter Maydell
Date Feb. 25, 2013, 5:08 p.m.
Message ID <1361812142-26640-2-git-send-email-peter.maydell@linaro.org>
Download mbox | patch
Permalink /patch/222985/
State New
Headers show

Comments

Peter Maydell - Feb. 25, 2013, 5:08 p.m.
Make the SysBusDeviceClass::init optional, for devices which
genuinely don't need to do anything here. In particular, simple
devices which can do all their initialization in their
instance_init method don't need either a DeviceClass::realize
or SysBusDeviceClass::init method.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Acked-by: Andreas Färber <afaerber@suse.de>
---
 hw/sysbus.c |    3 +++
 1 file changed, 3 insertions(+)
Peter Crosthwaite - March 4, 2013, 2:23 a.m.
On Tue, Feb 26, 2013 at 3:08 AM, Peter Maydell <peter.maydell@linaro.org> wrote:
> Make the SysBusDeviceClass::init optional, for devices which
> genuinely don't need to do anything here. In particular, simple
> devices which can do all their initialization in their
> instance_init method don't need either a DeviceClass::realize
> or SysBusDeviceClass::init method.
>
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> Acked-by: Andreas Färber <afaerber@suse.de>

Reviewed-by: Peter Crosthwaite <peter.crosthwaite@xilinx.com>

> ---
>  hw/sysbus.c |    3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/hw/sysbus.c b/hw/sysbus.c
> index 6d9d1df..e9a16ac 100644
> --- a/hw/sysbus.c
> +++ b/hw/sysbus.c
> @@ -118,6 +118,9 @@ static int sysbus_device_init(DeviceState *dev)
>      SysBusDevice *sd = SYS_BUS_DEVICE(dev);
>      SysBusDeviceClass *sbc = SYS_BUS_DEVICE_GET_CLASS(sd);
>
> +    if (!sbc->init) {
> +        return 0;
> +    }
>      return sbc->init(sd);
>  }
>
> --
> 1.7.9.5
>
>

Patch

diff --git a/hw/sysbus.c b/hw/sysbus.c
index 6d9d1df..e9a16ac 100644
--- a/hw/sysbus.c
+++ b/hw/sysbus.c
@@ -118,6 +118,9 @@  static int sysbus_device_init(DeviceState *dev)
     SysBusDevice *sd = SYS_BUS_DEVICE(dev);
     SysBusDeviceClass *sbc = SYS_BUS_DEVICE_GET_CLASS(sd);
 
+    if (!sbc->init) {
+        return 0;
+    }
     return sbc->init(sd);
 }