From patchwork Mon Oct 9 16:41:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 731010 Delivered-To: patch@linaro.org Received: by 2002:a5d:574c:0:b0:31d:da82:a3b4 with SMTP id q12csp1311696wrw; Mon, 9 Oct 2023 09:44:46 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFpD9QV0M9ZjxCq7l5LPakyl/h4OP7WTtMlSCeViiAi8eGAPK9cSAOLqB4kTGLlViZ5yIw8 X-Received: by 2002:a0d:e28f:0:b0:5a7:a792:a5d7 with SMTP id l137-20020a0de28f000000b005a7a792a5d7mr1284379ywe.15.1696869886486; Mon, 09 Oct 2023 09:44:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696869886; cv=none; d=google.com; s=arc-20160816; b=jAQh81ojP2OLA3Yn25u2zBJhinBKpd5p2+f2SD1H2UjL/AYW5uvYUfPY6u2TvPCU2P +Zh87sJe6XEAv9rtjK7rxtjdjOjC3s0LCI4nAy9HQucEsEx+xFHA18WKvLp4Ut5XLUGN otpkAY4dBHyXKPNtH8ZORgAsnEUs9wnR1qZuSvu4FryyEnAq+heOBqWsvxAV+Ks858RN +hKDZO2TmebWLpT1B3MLMEBzcMWlD/8wtCi77jl0C+SDSSfNPrsc29xvAhuj2cx3Z0In gImmU5UV/OUmUXSEkdKS/OdYIrU0E+iveisugBMDRBbUYHhlAdHLUK53tZRudCblyp+T YUfA== 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:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=SQaKCCtPdCExPYstQ0NllKjLPtp/IcVgNdDW/2dG2tw=; fh=hH+hY2AOPCtQWK44NzX0H5SWS0EYJFmL3o+I0zvKKVU=; b=rzyxeCxXsG6FbzTpnYEFIWodjcfjEIYS+YapIe5hXSmACuvZjNaTaIon0SfPdqWmkd YbtTn9NL/KRtxY0Nxpoy/jGI0zb/giL0/cTPc36Rd94jGBOjdtDGZu+kQrs2+xhjhTOT ZiyssmNCgz9Alty/XqAgLPdw8OMP1Zi+2JVc2lxkYGRE2lZ2Nsgb4tI5lBKF48bNxAU1 0c0789uWfKzP5uXJvgCog8AoWDXkYGXQdDTNKTauKxMjTFMgRZx87FT9tp1wFmX0DjeH HvjRn+YI4DLcFzytcWYC2qDns1RAGtYXwVeZRk6sRW5jxSZFA5FOfET8w3XysggLf7Ue IE5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=NE8ompUW; 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 h4-20020ac87d44000000b0041994a9c23asi6404644qtb.420.2023.10.09.09.44.46 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 09 Oct 2023 09:44:46 -0700 (PDT) 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=NE8ompUW; 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 1qptMQ-0002X6-8l; Mon, 09 Oct 2023 12:44:02 -0400 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 1qptKF-0005of-5n for qemu-devel@nongnu.org; Mon, 09 Oct 2023 12:41:47 -0400 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 1qptJj-0001bM-Ga for qemu-devel@nongnu.org; Mon, 09 Oct 2023 12:41:46 -0400 Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-40566f8a093so44170565e9.3 for ; Mon, 09 Oct 2023 09:41:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1696869674; x=1697474474; 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=SQaKCCtPdCExPYstQ0NllKjLPtp/IcVgNdDW/2dG2tw=; b=NE8ompUW6GgsAgWOO72/RgzPIQ6pQyPmamEeqmKAppzqJ9KKV3F2Qa5PreMGRyM+Ij nzv+5TtXFRJcSqDj1HWWFDfZzpLNYG/88PhStLlkltHxR/ecz7Bo2U9uZbWHAM6LMnuS e3mV7/XZLalUMxXjKNpTM3HhBdUXyEPdeimKlPvNTR+j0l1E7z7ws8nqOMp+uQFxlvte JLQscbD5u87UFQhbFi/csdjKYHeF0DShQ/8LraoIfLab3a9gE78jVDVkHnDLVzCTk16p gu5AhYbvg3hZ/IZMbSIEek8yXSKQ6RbX3ZlHTVjVgfTGsNFVDHco2rqVK8hwZB+a9h+u ajGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696869674; x=1697474474; 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=SQaKCCtPdCExPYstQ0NllKjLPtp/IcVgNdDW/2dG2tw=; b=pUQdtDEwnt2f+4fTss2qJK3QLBgdU4zsNe1HAjL1utd6s9mbs6675ib5Ej9y4U9Gpi 8NalSkndd1m0xmWmmgLA73jfr7DG9CDMXl9dVDWWrUSBWAD8/XhR3psW0ObVh3TUJkK0 yQyPik6nl/OYtF70uswgJnxDCU0rJjwF0Uen5IpU50Dzv/HVr7JMWOEhsWm74TosJkNT hBfThmBMu0Gl+mDAutPt/72X4bFrybFcrw6oNxC8dPu1B5avIiojPdeYH81qKnzFaRqQ tnArmauBDoqXoDsRXI0bNY/kZXrOlvXj59PZoyryO2Hd7Z33ySyT+2KPGrcdlnQnmBp+ iq8g== X-Gm-Message-State: AOJu0YzyTBhUwLT1moNkbZRHOLoJ/En1AEy0IXcpaOCIykHOtJGLUk+g h/qQVW9IrX4P/mwDjbrChiXM9w== X-Received: by 2002:a05:600c:210b:b0:405:1dbd:f77 with SMTP id u11-20020a05600c210b00b004051dbd0f77mr13591872wml.31.1696869674023; Mon, 09 Oct 2023 09:41:14 -0700 (PDT) Received: from zen.linaroharston ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id m7-20020a05600c280700b004047ac770d1sm13913102wmb.8.2023.10.09.09.41.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 09:41:11 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id D4BE31FFBD; Mon, 9 Oct 2023 17:41:07 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Thomas Huth , Xiaojuan Yang , =?utf-8?q?C=C3=A9dric_Le_Goater?= , =?utf-8?q?Alex_Benn=C3=A9?= =?utf-8?q?e?= , Bastian Koppelmann , Brad Smith , Radoslaw Biernacki , David Hildenbrand , Cleber Rosa , Ilya Leoshkevich , qemu-riscv@nongnu.org, Daniel Henrique Barboza , Alexandre Iooss , Nicholas Piggin , Bin Meng , Leif Lindholm , Paolo Bonzini , Eduardo Habkost , Alistair Francis , qemu-ppc@nongnu.org, John Snow , Liu Zhiwei , qemu-arm@nongnu.org, Wainer dos Santos Moschetta , Palmer Dabbelt , Peter Maydell , Yanan Wang , Weiwei Li , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Marcel Apfelbaum , Beraldo Leal , Yoshinori Sato , Mahmoud Mandour , Richard Henderson , Song Gao , Marcin Juszkiewicz , qemu-s390x@nongnu.org, =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH 23/25] contrib/plugins: fix coverity warning in cache Date: Mon, 9 Oct 2023 17:41:02 +0100 Message-Id: <20231009164104.369749-24-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231009164104.369749-1-alex.bennee@linaro.org> References: <20231009164104.369749-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32d; envelope-from=alex.bennee@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 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 Coverity complains that appends_stats_line can be fed a 0 leading to the undefined behaviour of a divide by 0. Fixes: CID 1519044 Fixes: CID 1519047 Signed-off-by: Alex Bennée --- contrib/plugins/cache.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/contrib/plugins/cache.c b/contrib/plugins/cache.c index 4fca3edd07..9e7ade3b37 100644 --- a/contrib/plugins/cache.c +++ b/contrib/plugins/cache.c @@ -535,15 +535,13 @@ static void caches_free(Cache **caches) } } -static void append_stats_line(GString *line, uint64_t l1_daccess, - uint64_t l1_dmisses, uint64_t l1_iaccess, - uint64_t l1_imisses, uint64_t l2_access, - uint64_t l2_misses) +static void append_stats_line(GString *line, + uint64_t l1_daccess, uint64_t l1_dmisses, + uint64_t l1_iaccess, uint64_t l1_imisses, + uint64_t l2_access, uint64_t l2_misses) { - double l1_dmiss_rate, l1_imiss_rate, l2_miss_rate; - - l1_dmiss_rate = ((double) l1_dmisses) / (l1_daccess) * 100.0; - l1_imiss_rate = ((double) l1_imisses) / (l1_iaccess) * 100.0; + double l1_dmiss_rate = ((double) l1_dmisses) / (l1_daccess) * 100.0; + double l1_imiss_rate = ((double) l1_imisses) / (l1_iaccess) * 100.0; g_string_append_printf(line, "%-14" PRIu64 " %-12" PRIu64 " %9.4lf%%" " %-14" PRIu64 " %-12" PRIu64 " %9.4lf%%", @@ -554,8 +552,8 @@ static void append_stats_line(GString *line, uint64_t l1_daccess, l1_imisses, l1_iaccess ? l1_imiss_rate : 0.0); - if (use_l2) { - l2_miss_rate = ((double) l2_misses) / (l2_access) * 100.0; + if (l2_access && l2_misses) { + double l2_miss_rate = ((double) l2_misses) / (l2_access) * 100.0; g_string_append_printf(line, " %-12" PRIu64 " %-11" PRIu64 " %10.4lf%%", l2_access,