Revision da3bd642 hw/block/pflash_cfi02.c

b/hw/block/pflash_cfi02.c
592 592
    .endianness = DEVICE_NATIVE_ENDIAN,
593 593
};
594 594

  
595
static int pflash_cfi02_init(SysBusDevice *dev)
595
static void pflash_cfi02_realize(DeviceState *dev, Error **errp)
596 596
{
597 597
    pflash_t *pfl = CFI_PFLASH02(dev);
598 598
    uint32_t chip_len;
......
616 616
        /* read the initial flash content */
617 617
        ret = bdrv_read(pfl->bs, 0, pfl->storage, chip_len >> 9);
618 618
        if (ret < 0) {
619
            g_free(pfl);
620
            return 1;
619
            vmstate_unregister_ram(&pfl->orig_mem, DEVICE(pfl));
620
            memory_region_destroy(&pfl->orig_mem);
621
            error_setg(errp, "failed to read the initial flash content");
622
            return;
621 623
        }
622 624
    }
623 625

  
624 626
    pflash_setup_mappings(pfl);
625 627
    pfl->rom_mode = 1;
626
    sysbus_init_mmio(dev, &pfl->mem);
628
    sysbus_init_mmio(SYS_BUS_DEVICE(dev), &pfl->mem);
627 629

  
628 630
    if (pfl->bs) {
629 631
        pfl->ro = bdrv_is_read_only(pfl->bs);
......
712 714

  
713 715
    pfl->cfi_table[0x3b] = 0x00;
714 716
    pfl->cfi_table[0x3c] = 0x00;
715

  
716
    return 0;
717 717
}
718 718

  
719 719
static Property pflash_cfi02_properties[] = {
......
736 736
static void pflash_cfi02_class_init(ObjectClass *klass, void *data)
737 737
{
738 738
    DeviceClass *dc = DEVICE_CLASS(klass);
739
    SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
740 739

  
741
    k->init = pflash_cfi02_init;
740
    dc->realize = pflash_cfi02_realize;
742 741
    dc->props = pflash_cfi02_properties;
743 742
}
744 743

  

Also available in: Unified diff