From 8f1ffe5be8178aa7dd72c06ac4d65096d149c573 Mon Sep 17 00:00:00 2001 From: David Hildenbrand Date: Wed, 1 Aug 2018 15:34:41 +0200 Subject: pc-dimm: assign and verify the "slot" property during pre_plug We can assign and verify the slot before realizing and trying to plug. reading/writing the slot property should never fail, so let's reduce error handling a bit by using &error_abort. To do this during pre_plug, add and use (x86, ppc) pc_dimm_pre_plug(). Reviewed-by: David Gibson Reviewed-by: Igor Mammedov Reviewed-by: Eric Auger Signed-off-by: David Hildenbrand Message-Id: <20180801133444.11269-2-david@redhat.com> Signed-off-by: Paolo Bonzini --- hw/mem/pc-dimm.c | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) (limited to 'hw/mem/pc-dimm.c') diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c index 65843bc52a..e56c4daef2 100644 --- a/hw/mem/pc-dimm.c +++ b/hw/mem/pc-dimm.c @@ -29,10 +29,27 @@ static int pc_dimm_get_free_slot(const int *hint, int max_slots, Error **errp); +void pc_dimm_pre_plug(DeviceState *dev, MachineState *machine, Error **errp) +{ + Error *local_err = NULL; + int slot; + + slot = object_property_get_int(OBJECT(dev), PC_DIMM_SLOT_PROP, + &error_abort); + slot = pc_dimm_get_free_slot(slot == PC_DIMM_UNASSIGNED_SLOT ? NULL : &slot, + machine->ram_slots, &local_err); + if (local_err) { + goto out; + } + object_property_set_int(OBJECT(dev), slot, PC_DIMM_SLOT_PROP, &error_abort); + trace_mhp_pc_dimm_assigned_slot(slot); +out: + error_propagate(errp, local_err); +} + void pc_dimm_plug(DeviceState *dev, MachineState *machine, uint64_t align, Error **errp) { - int slot; PCDIMMDevice *dimm = PC_DIMM(dev); PCDIMMDeviceClass *ddc = PC_DIMM_GET_CLASS(dimm); MemoryRegion *vmstate_mr = ddc->get_vmstate_memory_region(dimm, @@ -59,22 +76,6 @@ void pc_dimm_plug(DeviceState *dev, MachineState *machine, uint64_t align, } trace_mhp_pc_dimm_assigned_address(addr); - slot = object_property_get_int(OBJECT(dev), PC_DIMM_SLOT_PROP, &local_err); - if (local_err) { - goto out; - } - - slot = pc_dimm_get_free_slot(slot == PC_DIMM_UNASSIGNED_SLOT ? NULL : &slot, - machine->ram_slots, &local_err); - if (local_err) { - goto out; - } - object_property_set_int(OBJECT(dev), slot, PC_DIMM_SLOT_PROP, &local_err); - if (local_err) { - goto out; - } - trace_mhp_pc_dimm_assigned_slot(slot); - memory_device_plug_region(machine, mr, addr); vmstate_register_ram(vmstate_mr, dev); -- cgit v1.2.3