aboutsummaryrefslogtreecommitdiff
path: root/hw/ppc
diff options
context:
space:
mode:
authorGreg Kurz <groug@kaod.org>2017-10-12 18:30:23 +0200
committerDavid Gibson <david@gibson.dropbear.id.au>2017-10-17 10:34:01 +1100
commite7cca3e94f7595b7b5a493a87146e782831611d7 (patch)
tree1c96ff476233e23ada17202f0c2755cbb5b99001 /hw/ppc
parentf7d6bfcdc0fe49040aac3ac131a319cb5427957e (diff)
spapr_cpu_core: rewrite machine type sanity check
This makes the code easier to understand and it is consistent with what we already do for PHBs. Signed-off-by: Greg Kurz <groug@kaod.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Diffstat (limited to 'hw/ppc')
-rw-r--r--hw/ppc/spapr_cpu_core.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/hw/ppc/spapr_cpu_core.c b/hw/ppc/spapr_cpu_core.c
index 195762d8d2..3a4c174012 100644
--- a/hw/ppc/spapr_cpu_core.c
+++ b/hw/ppc/spapr_cpu_core.c
@@ -137,7 +137,12 @@ error:
static void spapr_cpu_core_realize(DeviceState *dev, Error **errp)
{
- sPAPRMachineState *spapr;
+ /* We don't use SPAPR_MACHINE() in order to exit gracefully if the user
+ * tries to add a sPAPR CPU core to a non-pseries machine.
+ */
+ sPAPRMachineState *spapr =
+ (sPAPRMachineState *) object_dynamic_cast(qdev_get_machine(),
+ TYPE_SPAPR_MACHINE);
sPAPRCPUCore *sc = SPAPR_CPU_CORE(OBJECT(dev));
sPAPRCPUCoreClass *scc = SPAPR_CPU_CORE_GET_CLASS(OBJECT(dev));
CPUCore *cc = CPU_CORE(OBJECT(dev));
@@ -146,9 +151,8 @@ static void spapr_cpu_core_realize(DeviceState *dev, Error **errp)
void *obj;
int i, j;
- spapr = (sPAPRMachineState *) qdev_get_machine();
- if (!object_dynamic_cast((Object *) spapr, TYPE_SPAPR_MACHINE)) {
- error_setg(errp, "spapr-cpu-core needs a pseries machine");
+ if (!spapr) {
+ error_setg(errp, TYPE_SPAPR_CPU_CORE " needs a pseries machine");
return;
}