From db895a1e6a97e919f9b86d60c969377357b05066 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20F=C3=A4rber?= Date: Sun, 25 Nov 2012 02:37:14 +0100 Subject: isa: Use realizefn for ISADevice MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Drop ISADeviceClass::init and the resulting no-op initfn and let children implement their own realizefn. Adapt error handling. Split off an instance_init where sensible. Signed-off-by: Andreas Färber --- hw/char/debugcon.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'hw/char/debugcon.c') diff --git a/hw/char/debugcon.c b/hw/char/debugcon.c index 3b0637d44f..f254841aec 100644 --- a/hw/char/debugcon.c +++ b/hw/char/debugcon.c @@ -81,27 +81,32 @@ static const MemoryRegionOps debugcon_ops = { .endianness = DEVICE_LITTLE_ENDIAN, }; -static void debugcon_init_core(DebugconState *s) +static void debugcon_realize_core(DebugconState *s, Error **errp) { if (!s->chr) { - fprintf(stderr, "Can't create debugcon device, empty char device\n"); - exit(1); + error_setg(errp, "Can't create debugcon device, empty char device"); + return; } qemu_chr_add_handlers(s->chr, NULL, NULL, NULL, s); } -static int debugcon_isa_initfn(ISADevice *dev) +static void debugcon_isa_realizefn(DeviceState *dev, Error **errp) { + ISADevice *d = ISA_DEVICE(dev); ISADebugconState *isa = ISA_DEBUGCON_DEVICE(dev); DebugconState *s = &isa->state; + Error *err = NULL; - debugcon_init_core(s); + debugcon_realize_core(s, &err); + if (err != NULL) { + error_propagate(errp, err); + return; + } memory_region_init_io(&s->io, &debugcon_ops, s, TYPE_ISA_DEBUGCON_DEVICE, 1); - memory_region_add_subregion(isa_address_space_io(dev), + memory_region_add_subregion(isa_address_space_io(d), isa->iobase, &s->io); - return 0; } static Property debugcon_isa_properties[] = { @@ -114,8 +119,8 @@ static Property debugcon_isa_properties[] = { static void debugcon_isa_class_initfn(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); - ISADeviceClass *ic = ISA_DEVICE_CLASS(klass); - ic->init = debugcon_isa_initfn; + + dc->realize = debugcon_isa_realizefn; dc->props = debugcon_isa_properties; } -- cgit v1.2.1