From patchwork Thu Oct 12 16:30:23 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kurz X-Patchwork-Id: 824950 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yCbvW3nSLz9t39 for ; Fri, 13 Oct 2017 03:31:19 +1100 (AEDT) Received: from localhost ([::1]:46450 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2gOD-0007iK-DF for incoming@patchwork.ozlabs.org; Thu, 12 Oct 2017 12:31:17 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52695) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2gNT-0007aS-5H for qemu-devel@nongnu.org; Thu, 12 Oct 2017 12:30:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e2gNP-0002Cw-7o for qemu-devel@nongnu.org; Thu, 12 Oct 2017 12:30:31 -0400 Received: from 5.mo177.mail-out.ovh.net ([46.105.39.154]:36479) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e2gNP-0002CP-0n for qemu-devel@nongnu.org; Thu, 12 Oct 2017 12:30:27 -0400 Received: from player688.ha.ovh.net (b6.ovh.net [213.186.33.56]) by mo177.mail-out.ovh.net (Postfix) with ESMTP id AB6B2863E8 for ; Thu, 12 Oct 2017 18:30:25 +0200 (CEST) Received: from bahia.lab.toulouse-stg.fr.ibm.com (deibp9eh1--blueice1n3.emea.ibm.com [195.212.29.165]) (Authenticated sender: groug@kaod.org) by player688.ha.ovh.net (Postfix) with ESMTPA id 71D4E2008B; Thu, 12 Oct 2017 18:30:23 +0200 (CEST) From: Greg Kurz To: qemu-devel@nongnu.org Date: Thu, 12 Oct 2017 18:30:23 +0200 Message-ID: <150782582319.2204.272473445471969673.stgit@bahia.lab.toulouse-stg.fr.ibm.com> In-Reply-To: <150782581468.2204.675461686446925339.stgit@bahia.lab.toulouse-stg.fr.ibm.com> References: <150782581468.2204.675461686446925339.stgit@bahia.lab.toulouse-stg.fr.ibm.com> User-Agent: StGit/0.17.1-46-g6855-dirty MIME-Version: 1.0 X-Ovh-Tracer-Id: 10998071765737183571 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedttddrtdeggdektdcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 46.105.39.154 Subject: [Qemu-devel] [PATCH v3 2/2] spapr_cpu_core: rewrite machine type sanity check X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-ppc@nongnu.org, David Gibson Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" This makes the code easier to understand and it is consistent with what we already do for PHBs. Signed-off-by: Greg Kurz --- hw/ppc/spapr_cpu_core.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/hw/ppc/spapr_cpu_core.c b/hw/ppc/spapr_cpu_core.c index 195762d8d266..3a4c17401226 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; }