diff options
Diffstat (limited to 'hw')
-rw-r--r-- | hw/i386/pc.c | 4 | ||||
-rw-r--r-- | hw/mem/pc-dimm.c | 32 |
2 files changed, 24 insertions, 12 deletions
diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 2ec45a4be0..c7af6aae01 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -1584,8 +1584,8 @@ static void pc_dimm_plug(HotplugHandler *hotplug_dev, goto out; } - if (pc_existing_dimms_capacity(OBJECT(machine), &existing_dimms_capacity)) { - error_setg(&local_err, "failed to get total size of existing DIMMs"); + existing_dimms_capacity = pc_existing_dimms_capacity(&local_err); + if (local_err) { goto out; } diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c index f02ce6e04c..18cdc54bf9 100644 --- a/hw/mem/pc-dimm.c +++ b/hw/mem/pc-dimm.c @@ -22,32 +22,44 @@ #include "qemu/config-file.h" #include "qapi/visitor.h" #include "qemu/range.h" -#include "qapi/qmp/qerror.h" -int pc_existing_dimms_capacity(Object *obj, void *opaque) +typedef struct pc_dimms_capacity { + uint64_t size; + Error **errp; +} pc_dimms_capacity; + +static int pc_existing_dimms_capacity_internal(Object *obj, void *opaque) { - Error *local_err = NULL; - uint64_t *size = opaque; + pc_dimms_capacity *cap = opaque; + uint64_t *size = &cap->size; if (object_dynamic_cast(obj, TYPE_PC_DIMM)) { DeviceState *dev = DEVICE(obj); if (dev->realized) { (*size) += object_property_get_int(obj, PC_DIMM_SIZE_PROP, - &local_err); + cap->errp); } - if (local_err) { - qerror_report_err(local_err); - error_free(local_err); + if (cap->errp && *cap->errp) { return 1; } } - - object_child_foreach(obj, pc_existing_dimms_capacity, opaque); + object_child_foreach(obj, pc_existing_dimms_capacity_internal, opaque); return 0; } +uint64_t pc_existing_dimms_capacity(Error **errp) +{ + pc_dimms_capacity cap; + + cap.size = 0; + cap.errp = errp; + + pc_existing_dimms_capacity_internal(qdev_get_machine(), &cap); + return cap.size; +} + int qmp_pc_dimm_device_list(Object *obj, void *opaque) { MemoryDeviceInfoList ***prev = opaque; |