From nobody Tue Nov 26 22:30:49 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1704470231; cv=none; d=zohomail.com; s=zohoarc; b=IcQe/5ijuXDehKB+0/eR0R7HVhVC3zuqKyhfWdvUydJGwVx7UTVVepe/vW6MVGlFLGFL4TTAZpp6QgIZoHCGVaB/FDfoDIBgai3GGq40S2qO61smcwx9I1YWSsTNkJ8SEG64wCdkHKjU4/Mv/kFRl0udjMQPLaeAQC75HM68qDg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1704470231; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=1OMJ2J/9TeJEsVbvbtgjbGV5MuipQ2Dh2Ow8E2AaclY=; b=lEoD9n4qd4Rf3+nltzypDtleaYJe/N+QGU4sH9HZetn2TBnUOvXuwmviqTvhHpBdTRbYpiLxERHLzl/bGMeKfc+PLXimVJH+ggD2F9L68jCQXR1i69gPNC5kMktfi3JnS+2m7o+pXztH3wVZuO6R/jIcKqXbNJjangiN0bBpoU8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1704470231920215.09489254395442; Fri, 5 Jan 2024 07:57:11 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rLmPe-0004qI-BN; Fri, 05 Jan 2024 10:47:11 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rLmOj-0001wJ-3V for qemu-devel@nongnu.org; Fri, 05 Jan 2024 10:46:14 -0500 Received: from mail-wm1-x32d.google.com ([2a00:1450:4864:20::32d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rLmOe-0003pA-RC for qemu-devel@nongnu.org; Fri, 05 Jan 2024 10:46:12 -0500 Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-40d5336986cso18963555e9.1 for ; Fri, 05 Jan 2024 07:46:07 -0800 (PST) Received: from m1x-phil.lan (juv34-h02-176-184-26-1.dsl.sta.abo.bbox.fr. [176.184.26.1]) by smtp.gmail.com with ESMTPSA id p15-20020a05600c358f00b0040d90407f7esm1931456wmq.8.2024.01.05.07.46.05 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 05 Jan 2024 07:46:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1704469566; x=1705074366; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=1OMJ2J/9TeJEsVbvbtgjbGV5MuipQ2Dh2Ow8E2AaclY=; b=Q1SsD5VVAHJmO+jOod0cqpLhrRuuvNV3fyxFAkIeyZmyfL74xygwDD/J1dpm8oLjbR msuNkNT5Yt2vB5CLgIU7YjX8GB91mEJogAFOZb44BtDKX/SRjjcrdB26exdEO0W4OfAR KuB1wZiNSrsRSbCQK0Vzd0SIZDiV2PLs5MQs6Nh4V3AQFC5++K3GXJ9Brar7sPdTaN+U stc5Mh8+zCwkmKMfdUup+UJfGKDYAHDCXuys27hYGnVsFDmwOcIPsm0wsZ8Cr7hw9kKu OvFfPOl4SV0J9udBgy9HB+hqsKuulC55LBe4CMSGy2yCYh1GSyuGqc/xWK81Del+p9Ag AOww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704469566; x=1705074366; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1OMJ2J/9TeJEsVbvbtgjbGV5MuipQ2Dh2Ow8E2AaclY=; b=FBtPXNa5GSQqxAEpHv8wPVJSlb11eHPoX7xnl5o/OffYzP7koX6Z1wfsEhZ7q6GzzJ PoRvNc/+L8YZZu56Awrs970RwiJ4rBaveKgHPQv+blkC2jx9EJdgOh+30+AdcrhmHHNT r0v9k5ah91yBWqdvzwMu6hQtsNRHjTYl/tLW8YQbVrNlC29vO4BBHCf4vY5pg52jCkca rPerOf5Iod8OzYlW64PqfscvNoKZhMLRnkLuZaAd4aUvIJ0tuZrNG4kxxe82ylsxo2Gu ndYUDNbBAn1/z8oO5HPBukNzVxERhaZ/GzDHoJJ3CJ/CzF/tQyc/Xjrho/F3blWNRbAt 4RMg== X-Gm-Message-State: AOJu0YwY2z+s2/lMGc+/MojJPEu1L9zP8iOPoLUvE2/AaQ9mhxvO5zuH TiAVGpuvzTGRiwABnPDjzUdp8jD9cuwBa6j334OFjrmanRg= X-Google-Smtp-Source: AGHT+IFRxnhVVDCfQBopyfbXhH7RtM2Ah4+sNf5mWm1YUcourIH6uZAJTYc6GI0mRZhX+CMRCdg9EQ== X-Received: by 2002:a05:600c:1d82:b0:40e:36ba:e51a with SMTP id p2-20020a05600c1d8200b0040e36bae51amr729802wms.132.1704469566494; Fri, 05 Jan 2024 07:46:06 -0800 (PST) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: qemu-ppc@nongnu.org, qemu-arm@nongnu.org, qemu-riscv@nongnu.org, Gavin Shan , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Eduardo Habkost , Marcel Apfelbaum , Yanan Wang Subject: [PULL 26/71] machine: Improve is_cpu_type_supported() Date: Fri, 5 Jan 2024 16:42:19 +0100 Message-ID: <20240105154307.21385-27-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240105154307.21385-1-philmd@linaro.org> References: <20240105154307.21385-1-philmd@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::32d; envelope-from=philmd@linaro.org; helo=mail-wm1-x32d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1704470233822100001 From: Gavin Shan It's no sense to check the CPU type when mc->valid_cpu_types[0] is NULL, which is a program error. Raise an assert on this. A precise hint for the error message is given when mc->valid_cpu_types[0] is the only valid entry. Besides, enumeration on mc->valid_cpu_types[0] when we have mutiple valid entries there is avoided to increase the code readability, as suggested by Philippe Mathieu-Daud=C3=A9. Besides, @cc comes from machine->cpu_type or mc->default_cpu_type. For the later case, it can be NULL and it's also a program error. We should use assert() in this case. Signed-off-by: Gavin Shan Message-ID: <20231204004726.483558-4-gshan@redhat.com> Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- hw/core/machine.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/hw/core/machine.c b/hw/core/machine.c index 0119b11fc8..c523ce32eb 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -1412,6 +1412,7 @@ static bool is_cpu_type_supported(const MachineState = *machine, Error **errp) * type is provided through '-cpu' option. */ if (mc->valid_cpu_types) { + assert(mc->valid_cpu_types[0] !=3D NULL); for (i =3D 0; mc->valid_cpu_types[i]; i++) { if (object_class_dynamic_cast(oc, mc->valid_cpu_types[i])) { break; @@ -1421,20 +1422,27 @@ static bool is_cpu_type_supported(const MachineStat= e *machine, Error **errp) /* The user specified CPU type isn't valid */ if (!mc->valid_cpu_types[i]) { error_setg(errp, "Invalid CPU type: %s", machine->cpu_type); - error_append_hint(errp, "The valid types are: %s", - mc->valid_cpu_types[0]); - for (i =3D 1; mc->valid_cpu_types[i]; i++) { - error_append_hint(errp, ", %s", mc->valid_cpu_types[i]); + if (!mc->valid_cpu_types[1]) { + error_append_hint(errp, "The only valid type is: %s\n", + mc->valid_cpu_types[0]); + } else { + error_append_hint(errp, "The valid types are: "); + for (i =3D 0; mc->valid_cpu_types[i]; i++) { + error_append_hint(errp, "%s%s", + mc->valid_cpu_types[i], + mc->valid_cpu_types[i + 1] ? ", " : = ""); + } + error_append_hint(errp, "\n"); } =20 - error_append_hint(errp, "\n"); return false; } } =20 /* Check if CPU type is deprecated and warn if so */ cc =3D CPU_CLASS(oc); - if (cc && cc->deprecation_note) { + assert(cc !=3D NULL); + if (cc->deprecation_note) { warn_report("CPU model %s is deprecated -- %s", machine->cpu_type, cc->deprecation_note); } --=20 2.41.0