memory: add parameter errp to memory_region_init_rom_device

Add parameter errp to memory_region_init_rom_device and update all call
sites to propagate the error.

Reviewed-by: Peter Crosthwaite <peter.crosthwaite@xilinx.com>
Signed-off-by: Hu Tao <hutao@cn.fujitsu.com>
[Propagate the error out of realize. - Paolo]
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
Hu Tao 2014-09-09 13:27:57 +08:00 committed by Paolo Bonzini
parent 49946538d2
commit 33e0eb5297
4 changed files with 20 additions and 5 deletions

View File

@ -750,6 +750,7 @@ static void pflash_cfi01_realize(DeviceState *dev, Error **errp)
int ret; int ret;
uint64_t blocks_per_device, device_len; uint64_t blocks_per_device, device_len;
int num_devices; int num_devices;
Error *local_err = NULL;
total_len = pfl->sector_len * pfl->nb_blocs; total_len = pfl->sector_len * pfl->nb_blocs;
@ -770,7 +771,12 @@ static void pflash_cfi01_realize(DeviceState *dev, Error **errp)
memory_region_init_rom_device( memory_region_init_rom_device(
&pfl->mem, OBJECT(dev), &pfl->mem, OBJECT(dev),
pfl->be ? &pflash_cfi01_ops_be : &pflash_cfi01_ops_le, pfl, pfl->be ? &pflash_cfi01_ops_be : &pflash_cfi01_ops_le, pfl,
pfl->name, total_len); pfl->name, total_len, &local_err);
if (local_err) {
error_propagate(errp, local_err);
return;
}
vmstate_register_ram(&pfl->mem, DEVICE(pfl)); vmstate_register_ram(&pfl->mem, DEVICE(pfl));
pfl->storage = memory_region_get_ram_ptr(&pfl->mem); pfl->storage = memory_region_get_ram_ptr(&pfl->mem);
sysbus_init_mmio(SYS_BUS_DEVICE(dev), &pfl->mem); sysbus_init_mmio(SYS_BUS_DEVICE(dev), &pfl->mem);

View File

@ -597,6 +597,7 @@ static void pflash_cfi02_realize(DeviceState *dev, Error **errp)
pflash_t *pfl = CFI_PFLASH02(dev); pflash_t *pfl = CFI_PFLASH02(dev);
uint32_t chip_len; uint32_t chip_len;
int ret; int ret;
Error *local_err = NULL;
chip_len = pfl->sector_len * pfl->nb_blocs; chip_len = pfl->sector_len * pfl->nb_blocs;
/* XXX: to be fixed */ /* XXX: to be fixed */
@ -608,7 +609,12 @@ static void pflash_cfi02_realize(DeviceState *dev, Error **errp)
memory_region_init_rom_device(&pfl->orig_mem, OBJECT(pfl), pfl->be ? memory_region_init_rom_device(&pfl->orig_mem, OBJECT(pfl), pfl->be ?
&pflash_cfi02_ops_be : &pflash_cfi02_ops_le, &pflash_cfi02_ops_be : &pflash_cfi02_ops_le,
pfl, pfl->name, chip_len); pfl, pfl->name, chip_len, &local_err);
if (local_err) {
error_propagate(errp, local_err);
return;
}
vmstate_register_ram(&pfl->orig_mem, DEVICE(pfl)); vmstate_register_ram(&pfl->orig_mem, DEVICE(pfl));
pfl->storage = memory_region_get_ram_ptr(&pfl->orig_mem); pfl->storage = memory_region_get_ram_ptr(&pfl->orig_mem);
pfl->chip_len = chip_len; pfl->chip_len = chip_len;

View File

@ -386,13 +386,15 @@ void memory_region_init_alias(MemoryRegion *mr,
* @ops: callbacks for write access handling. * @ops: callbacks for write access handling.
* @name: the name of the region. * @name: the name of the region.
* @size: size of the region. * @size: size of the region.
* @errp: pointer to Error*, to store an error if it happens.
*/ */
void memory_region_init_rom_device(MemoryRegion *mr, void memory_region_init_rom_device(MemoryRegion *mr,
struct Object *owner, struct Object *owner,
const MemoryRegionOps *ops, const MemoryRegionOps *ops,
void *opaque, void *opaque,
const char *name, const char *name,
uint64_t size); uint64_t size,
Error **errp);
/** /**
* memory_region_init_reservation: Initialize a memory region that reserves * memory_region_init_reservation: Initialize a memory region that reserves

View File

@ -1204,7 +1204,8 @@ void memory_region_init_rom_device(MemoryRegion *mr,
const MemoryRegionOps *ops, const MemoryRegionOps *ops,
void *opaque, void *opaque,
const char *name, const char *name,
uint64_t size) uint64_t size,
Error **errp)
{ {
memory_region_init(mr, owner, name, size); memory_region_init(mr, owner, name, size);
mr->ops = ops; mr->ops = ops;
@ -1212,7 +1213,7 @@ void memory_region_init_rom_device(MemoryRegion *mr,
mr->terminates = true; mr->terminates = true;
mr->rom_device = true; mr->rom_device = true;
mr->destructor = memory_region_destructor_rom_device; mr->destructor = memory_region_destructor_rom_device;
mr->ram_addr = qemu_ram_alloc(size, mr, &error_abort); mr->ram_addr = qemu_ram_alloc(size, mr, errp);
} }
void memory_region_init_iommu(MemoryRegion *mr, void memory_region_init_iommu(MemoryRegion *mr,