From patchwork Thu Jan 11 06:47:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 761793 Delivered-To: patch@linaro.org Received: by 2002:a5d:6e02:0:b0:337:62d3:c6d5 with SMTP id h2csp2255881wrz; Wed, 10 Jan 2024 22:48:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IH5+JztgbfkMoOA5PBDPmyAaRoF0YTzJ1F16PM9NK4utlbwMPWjl2ni0XMrs/5GPQKfV2Dq X-Received: by 2002:a05:622a:c9:b0:429:b012:e6e6 with SMTP id p9-20020a05622a00c900b00429b012e6e6mr252568qtw.131.1704955729348; Wed, 10 Jan 2024 22:48:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704955729; cv=none; d=google.com; s=arc-20160816; b=qlz2xnppx4n9f6HpknZPpSRR6yH+amlTV4B+ujewwtlxwEmjaZ8gD+yifY6mzgdwh0 tTwYcfG+U0hoyZChnMz2fFU9p+vu1lbELJ9xWQE8gipKxP+UFUQo4Jx/6MnjyHztepnY yE2eUyXmhM0tQ2yVob332ZUVeMSRU9MTWaUHRK6Q1XivT6X1OSBm0DG0fBqBqKI8zG93 TQV0ytkxz2MHxTTQgxTtJUBrXWanjBnHGUQj/1bOGmhPZb4DLvsbh4XdXJhc37lNRMfY wJYJpt9Thuk0zPTHVQvDAKkpgmQ5PkKpJpElmEti5CbIZz7AhfaXlaoPJsWpU1K2pePu 9hTQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature; bh=b4rLIFz3jamF5IQE8fOjn3Vo0LdIj7ZxS3Uv6QB7pgQ=; fh=JefIpm4funR4Ubr6bsJno+n37lrkDu19bdG5jSNSD/0=; b=Q3qUw74OS14vZXX8hfk2/eapNQrlihKXpGxzVvIyQT3NBTRoHde8QYgVNhjyrP63xv p1XoUMTkxMv4OpgDdtqnJlM3V52IH50dHhbTAVO2uGMGsM6O4hy04XAylew7Bhtkq9Wt 1p3x7Oe8Wf9YFkwILTj19H3zg2Oyif4jR/OyXT/nb1bqkN0frJMUNO7luFrnJoM9pVEu cn8N8oIskWbeEyrKg3vvhgvByzbVQ7bibu5cXZ2B+FPCm0Qk4aFdbhA6rdAZRy+LAh8o V0CMYER8EgyYy7kIWBqA6puSxZ11H6BSwgygAwwswwRrBP2cmx4NEVM7vvvybM5yWafb l35Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=BBhCz0cd; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id w17-20020a05622a191100b004297709a946si408140qtc.124.2024.01.10.22.48.49 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 10 Jan 2024 22:48:49 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=BBhCz0cd; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rNoqm-0006PL-GS; Thu, 11 Jan 2024 01:47:36 -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 1rNoqj-0006Ox-IO for qemu-devel@nongnu.org; Thu, 11 Jan 2024 01:47:34 -0500 Received: from mail-wm1-x336.google.com ([2a00:1450:4864:20::336]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rNoqh-0001ls-VD for qemu-devel@nongnu.org; Thu, 11 Jan 2024 01:47:33 -0500 Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-40e60c01112so1401695e9.3 for ; Wed, 10 Jan 2024 22:47:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1704955648; x=1705560448; darn=nongnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=b4rLIFz3jamF5IQE8fOjn3Vo0LdIj7ZxS3Uv6QB7pgQ=; b=BBhCz0cdlfSOhO0QjesgQoylhYt+rh9Z+5Euz/KGxl3hdvxv2/YbWLVTm0TMwIXGXu o4ius9wWtxEIpRssJKxmgmsKED7ApvD6jTJs8fTJV9seZmBBacg7FD7lNdGckm6ahQTe ZTVl4A9wrPmSRjYEv1VFVlVFAYzZqrvvdnpFuatAeDPgBi6HJnJVL8YxgnkqeVyjKanz ebIr8hhY0EaxtLfuUh/ane1MarcB4pVhH5MAp4lbwv22RzSWkdKbf/y2cpGh19KCpoe8 EZXn7bypW1CA/oUXFmNF0LoVYClO1Ea1QRf7gznGKBKaSzZ5u3G3VlKSoc8ZmOHuq2jF simg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704955648; x=1705560448; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=b4rLIFz3jamF5IQE8fOjn3Vo0LdIj7ZxS3Uv6QB7pgQ=; b=SsLGZZr4aMn5mJ5NBnR8yXvRBG2yl70ymvmT7pzg7aQuGDQEuuqckF4phk7fib62ek fUBIok1mN6i2SXB2ad3iKV5Hg1wr7VenhGInkt4VSVpLuSejmeCVyGgGalLOdPXRaiMg weABaNFaHuXxli7B2KkoQlFK7onhzAN4f0FfxGhM6HHk4hWpPammywA8euEcdjSTXcwB 5K5s0uuwat4NMf9Ji1dkTSsO+hF0+WAtLvXGqDrWLXRQS+kX/MBxJzw3L9paT9YMeRPz 6Kb20Os4XmDLmG1jvwwWzrNTG5awY+ZXwxaN4WPKhbh1xAQM9vv130H6w7b4glYWDDp6 o3hA== X-Gm-Message-State: AOJu0Yxw1iAEYUyXG4le2OExICTu2SDXDaYpSSRue60a0fHN+ntiDJjU Aha44e2oNrMrC+YCoA1H6XdsiDKaoWFaXIf2za4q8eeHFuM= X-Received: by 2002:a05:600c:6cf:b0:40e:4e43:db55 with SMTP id b15-20020a05600c06cf00b0040e4e43db55mr105241wmn.70.1704955648385; Wed, 10 Jan 2024 22:47:28 -0800 (PST) Received: from m1x-phil.lan (vau06-h02-176-184-43-236.dsl.sta.abo.bbox.fr. [176.184.43.236]) by smtp.gmail.com with ESMTPSA id i10-20020a5d438a000000b00336344c3c3fsm359398wrq.90.2024.01.10.22.47.25 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 10 Jan 2024 22:47:28 -0800 (PST) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Daniel Henrique Barboza , =?utf-8?q?Philippe_Math?= =?utf-8?q?ieu-Daud=C3=A9?= , Paolo Bonzini , Yanan Wang , Nicholas Piggin , =?utf-8?q?C=C3=A9dric_Le_Goater?= , Richard Henderson , Marcel Apfelbaum , Eduardo Habkost , qemu-ppc@nongnu.org, Gavin Shan , Peter Maydell Subject: [PATCH] hw/core: Handle cpu_model_from_type() returning NULL value Date: Thu, 11 Jan 2024 07:47:23 +0100 Message-ID: <20240111064723.6920-1-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::336; envelope-from=philmd@linaro.org; helo=mail-wm1-x336.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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Per cpu_model_from_type() docstring (added in commit 445946f4dd): * Returns: CPU model name or NULL if the CPU class doesn't exist We must check the return value in order to avoid surprises, i.e.: $ qemu-system-arm -machine virt -cpu cortex-a9 qemu-system-arm: Invalid CPU model: cortex-a9 The valid models are: cortex-a7, cortex-a15, (null), (null), (null), (null), (null), (null), (null), (null), (null), (null), (null), max Add assertions when the call can not fail (because the CPU type must be registered). Fixes: 5422d2a8fa ("machine: Print CPU model name instead of CPU type") Reported-by: Peter Maydell Signed-off-by: Philippe Mathieu-Daudé --- cpu-target.c | 1 + hw/core/machine.c | 5 +++++ target/ppc/cpu_init.c | 1 + 3 files changed, 7 insertions(+) diff --git a/cpu-target.c b/cpu-target.c index 5eecd7ea2d..b0f6deb13b 100644 --- a/cpu-target.c +++ b/cpu-target.c @@ -291,6 +291,7 @@ static void cpu_list_entry(gpointer data, gpointer user_data) const char *typename = object_class_get_name(OBJECT_CLASS(data)); g_autofree char *model = cpu_model_from_type(typename); + assert(model); if (cc->deprecation_note) { qemu_printf(" %s (deprecated)\n", model); } else { diff --git a/hw/core/machine.c b/hw/core/machine.c index fc239101f9..730ec10328 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -1422,16 +1422,21 @@ static bool is_cpu_type_supported(const MachineState *machine, Error **errp) /* The user specified CPU type isn't valid */ if (!mc->valid_cpu_types[i]) { g_autofree char *requested = cpu_model_from_type(machine->cpu_type); + assert(requested); error_setg(errp, "Invalid CPU model: %s", requested); if (!mc->valid_cpu_types[1]) { g_autofree char *model = cpu_model_from_type( mc->valid_cpu_types[0]); + assert(model); error_append_hint(errp, "The only valid type is: %s\n", model); } else { error_append_hint(errp, "The valid models are: "); for (i = 0; mc->valid_cpu_types[i]; i++) { g_autofree char *model = cpu_model_from_type( mc->valid_cpu_types[i]); + if (!model) { + continue; + } error_append_hint(errp, "%s%s", model, mc->valid_cpu_types[i + 1] ? ", " : ""); diff --git a/target/ppc/cpu_init.c b/target/ppc/cpu_init.c index 344196a8ce..58f0c1e30e 100644 --- a/target/ppc/cpu_init.c +++ b/target/ppc/cpu_init.c @@ -7037,6 +7037,7 @@ static void ppc_cpu_list_entry(gpointer data, gpointer user_data) } name = cpu_model_from_type(typename); + assert(name); qemu_printf("PowerPC %-16s PVR %08x\n", name, pcc->pvr); for (i = 0; ppc_cpu_aliases[i].alias != NULL; i++) { PowerPCCPUAlias *alias = &ppc_cpu_aliases[i];