From patchwork Wed Sep 29 02:58:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "wangyanan (Y)" X-Patchwork-Id: 1534195 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4HK1cC5qMtz9svs for ; Wed, 29 Sep 2021 13:11:23 +1000 (AEST) Received: from localhost ([::1]:48774 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mVQ09-0002ip-Hf for incoming@patchwork.ozlabs.org; Tue, 28 Sep 2021 23:11:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60842) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mVPoB-0005oc-2B; Tue, 28 Sep 2021 22:58:59 -0400 Received: from szxga01-in.huawei.com ([45.249.212.187]:2936) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mVPo8-00068L-O0; Tue, 28 Sep 2021 22:58:58 -0400 Received: from dggemv711-chm.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4HK1Dr1nV7zbmsX; Wed, 29 Sep 2021 10:54:36 +0800 (CST) Received: from dggpemm500023.china.huawei.com (7.185.36.83) by dggemv711-chm.china.huawei.com (10.1.198.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Wed, 29 Sep 2021 10:58:53 +0800 Received: from DESKTOP-TMVL5KK.china.huawei.com (10.174.187.128) by dggpemm500023.china.huawei.com (7.185.36.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Wed, 29 Sep 2021 10:58:52 +0800 From: Yanan Wang To: Eduardo Habkost , Paolo Bonzini , =?utf-8?q?Daniel_P_=2E_Berrang=C3=A9?= , Andrew Jones , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , "Markus Armbruster" Subject: [PATCH v12 16/16] machine: Make smp_parse return a boolean Date: Wed, 29 Sep 2021 10:58:16 +0800 Message-ID: <20210929025816.21076-17-wangyanan55@huawei.com> X-Mailer: git-send-email 2.8.4.windows.1 In-Reply-To: <20210929025816.21076-1-wangyanan55@huawei.com> References: <20210929025816.21076-1-wangyanan55@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.174.187.128] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To dggpemm500023.china.huawei.com (7.185.36.83) X-CFilter-Loop: Reflected Received-SPF: pass client-ip=45.249.212.187; envelope-from=wangyanan55@huawei.com; helo=szxga01-in.huawei.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Pierre Morel , Pankaj Gupta , Cornelia Huck , qemu-devel@nongnu.org, Yanan Wang , qemu-s390x@nongnu.org, qemu-arm@nongnu.org, "Michael S . Tsirkin" , wanghaibin.wang@huawei.com, qemu-ppc@nongnu.org, David Gibson Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Quoting one of the Rules described in include/qapi/error.h: " Whenever practical, also return a value that indicates success / failure. This can make the error checking more concise, and can avoid useless error object creation and destruction. Note that we still have many functions returning void. We recommend • bool-valued functions return true on success / false on failure, • pointer-valued functions return non-null / null pointer, and • integer-valued functions return non-negative / negative. " So make smp_parse() return true on success and false on failure, so that we can more laconically check whether the parsing has succeeded without touching the errp. Suggested-by: Philippe Mathieu-Daudé Signed-off-by: Yanan Wang Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Daniel P. Berrangé Signed-off-by: Paolo Bonzini --- hw/core/machine.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/hw/core/machine.c b/hw/core/machine.c index 4dc936732e..3e3a2707af 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -788,7 +788,7 @@ static char *cpu_hierarchy_to_string(MachineState *ms) * introduced topology members which are likely to be target specific should * be directly set as 1 if they are omitted (e.g. dies for PC since 4.1). */ -static void smp_parse(MachineState *ms, SMPConfiguration *config, Error **errp) +static bool smp_parse(MachineState *ms, SMPConfiguration *config, Error **errp) { MachineClass *mc = MACHINE_GET_CLASS(ms); unsigned cpus = config->has_cpus ? config->cpus : 0; @@ -818,7 +818,7 @@ static void smp_parse(MachineState *ms, SMPConfiguration *config, Error **errp) */ if (!mc->smp_props.dies_supported && dies > 1) { error_setg(errp, "dies not supported by this machine's CPU topology"); - return; + return false; } dies = dies > 0 ? dies : 1; @@ -876,7 +876,7 @@ static void smp_parse(MachineState *ms, SMPConfiguration *config, Error **errp) "product of the hierarchy must match maxcpus: " "%s != maxcpus (%u)", topo_msg, maxcpus); - return; + return false; } if (maxcpus < cpus) { @@ -885,7 +885,7 @@ static void smp_parse(MachineState *ms, SMPConfiguration *config, Error **errp) "maxcpus must be equal to or greater than smp: " "%s == maxcpus (%u) < smp_cpus (%u)", topo_msg, maxcpus, cpus); - return; + return false; } if (ms->smp.cpus < mc->min_cpus) { @@ -893,7 +893,7 @@ static void smp_parse(MachineState *ms, SMPConfiguration *config, Error **errp) "supported by machine '%s' is %d", ms->smp.cpus, mc->name, mc->min_cpus); - return; + return false; } if (ms->smp.max_cpus > mc->max_cpus) { @@ -901,8 +901,10 @@ static void smp_parse(MachineState *ms, SMPConfiguration *config, Error **errp) "supported by machine '%s' is %d", ms->smp.max_cpus, mc->name, mc->max_cpus); - return; + return false; } + + return true; } static void machine_get_smp(Object *obj, Visitor *v, const char *name, @@ -933,8 +935,7 @@ static void machine_set_smp(Object *obj, Visitor *v, const char *name, return; } - smp_parse(ms, config, errp); - if (*errp) { + if (!smp_parse(ms, config, errp)) { qapi_free_SMPConfiguration(config); } }