Skip to content

Commit

Permalink
spapr: Simplify error path of spapr_core_plug()
Browse files Browse the repository at this point in the history
spapr_core_pre_plug() already guarantees that the slot for the given core
ID is available. It is thus safe to assume that spapr_find_cpu_slot()
returns a slot during plug. Turn the error path into an assertion.
It is also safe to assume that no device is attached to the corresponding
DRC and that spapr_drc_attach() shouldn't fail.

Pass &error_abort to spapr_drc_attach() and simplify error handling.

Signed-off-by: Greg Kurz <groug@kaod.org>
Message-Id: <20201201113728.885700-4-groug@kaod.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
  • Loading branch information
gkurz authored and dgibson committed Dec 14, 2020
1 parent 3764121 commit f9b4395
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions hw/ppc/spapr.c
Expand Up @@ -3738,8 +3738,7 @@ int spapr_core_dt_populate(SpaprDrc *drc, SpaprMachineState *spapr,
return 0;
}

static void spapr_core_plug(HotplugHandler *hotplug_dev, DeviceState *dev,
Error **errp)
static void spapr_core_plug(HotplugHandler *hotplug_dev, DeviceState *dev)
{
SpaprMachineState *spapr = SPAPR_MACHINE(OBJECT(hotplug_dev));
MachineClass *mc = MACHINE_GET_CLASS(spapr);
Expand All @@ -3754,20 +3753,20 @@ static void spapr_core_plug(HotplugHandler *hotplug_dev, DeviceState *dev,
int i;

core_slot = spapr_find_cpu_slot(MACHINE(hotplug_dev), cc->core_id, &index);
if (!core_slot) {
error_setg(errp, "Unable to find CPU core with core-id: %d",
cc->core_id);
return;
}
g_assert(core_slot); /* Already checked in spapr_core_pre_plug() */

drc = spapr_drc_by_id(TYPE_SPAPR_DRC_CPU,
spapr_vcpu_id(spapr, cc->core_id));

g_assert(drc || !mc->has_hotpluggable_cpus);

if (drc) {
if (!spapr_drc_attach(drc, dev, errp)) {
return;
}
/*
* spapr_core_pre_plug() already buys us this is a brand new
* core being plugged into a free slot. Nothing should already
* be attached to the corresponding DRC.
*/
spapr_drc_attach(drc, dev, &error_abort);

if (hotplugged) {
/*
Expand Down Expand Up @@ -4009,7 +4008,7 @@ static void spapr_machine_device_plug(HotplugHandler *hotplug_dev,
if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {
spapr_memory_plug(hotplug_dev, dev);
} else if (object_dynamic_cast(OBJECT(dev), TYPE_SPAPR_CPU_CORE)) {
spapr_core_plug(hotplug_dev, dev, errp);
spapr_core_plug(hotplug_dev, dev);
} else if (object_dynamic_cast(OBJECT(dev), TYPE_SPAPR_PCI_HOST_BRIDGE)) {
spapr_phb_plug(hotplug_dev, dev);
} else if (object_dynamic_cast(OBJECT(dev), TYPE_SPAPR_TPM_PROXY)) {
Expand Down

0 comments on commit f9b4395

Please sign in to comment.