From patchwork Mon Sep 25 14:48:47 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: 726039 Delivered-To: patch@linaro.org Received: by 2002:adf:ea87:0:b0:31d:da82:a3b4 with SMTP id s7csp2437517wrm; Mon, 25 Sep 2023 08:01:30 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFzIk+KRxVeoHwE9lWqPfRduVRTBzOy7ZjG4B253z7YzKmy6fTTPHF6QDecngNMbcNC35ph X-Received: by 2002:a05:620a:29c2:b0:774:2a7f:fa24 with SMTP id s2-20020a05620a29c200b007742a7ffa24mr6377271qkp.25.1695654090273; Mon, 25 Sep 2023 08:01:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695654090; cv=none; d=google.com; s=arc-20160816; b=oCAfU70wDFbj6sX8dbLu5jkR3L3uMpP7BBRq4bdcOvSwaWTVs23hfhDF6TzdITSPdo wa+A004GGsSY7i1iqb4UuUYgR2jHpPe4ZA7k5VSbgFgVQOWr/UJGSG++IhcS15bYKMtl VDJYiyhc10yPcvGKR4/UsUQzfQeCuPbocNWwNPnfDYOlR16mmPRLDUiJeL9a1f72xcBF EbfOsp4sL/6wQ/yz7jLu/VGxlx3iN2X6COI2ldiWCOa1VRcIu96InafntMRU7NVCpEQn g6gFtiBy4fxSxfQsZQ3vmVoHuoLVEpGfIXyOUHKrEJltOnV0b20+OslYUQOoAdgXEDnH gl8A== 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=f1HG4YWa+ndoxgBhrv2wvoi5B5rsQCa0P0+M/9TAKns=; b=HBWEwaF3uSZsGe7/555fVetLQ37iosMWY1Y+5T6pQkuZulHAEvKO/AbQjg55CM1c8F /e9z2VaQDvVDEN9w9HVYNXfxfZfPmmufobO7hVd+7ATpDnngEwzc5BjaRtNcOWw+WPhd X5uQ759EL/mDdG9A/waaeWlewWoLBWoKQ0qbUDr6ky3S/xwxEoiH8OK3gYn1j2ZLQB2L a88EXiwH64vcxUZgw28PFLvG4hU+yFHhgD5/SFefiV9HwcfN84a81JWFw6FYnbIVBcov 1JVjVjieXQf5nbF4xE8R5Zl1w8N8YvEwQ2UY7HPu8hMrC5HuD1/SITsq+DCypZqWS6Me h6Ag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dhq3eZbI; 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 vu17-20020a05620a561100b0076f1797fa7csi6145245qkn.534.2023.09.25.08.01.30 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 25 Sep 2023 08:01:30 -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=dhq3eZbI; 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 1qkn3Q-0000Ph-MM; Mon, 25 Sep 2023 10:59:20 -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 1qkn38-0008Lu-0n for qemu-devel@nongnu.org; Mon, 25 Sep 2023 10:59:03 -0400 Received: from mail-wm1-x32f.google.com ([2a00:1450:4864:20::32f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qkn2s-0002GF-To for qemu-devel@nongnu.org; Mon, 25 Sep 2023 10:59:00 -0400 Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-40566f8a093so34893415e9.3 for ; Mon, 25 Sep 2023 07:58:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1695653925; x=1696258725; 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=dhq3eZbIsX6rub1xZBO0zWvFWXHCRafGZ2iHkOIZUsolYzqAJOY3tLjb/dsPUqy+ko WRbLe/L31/BgUX5n39CXgxGmbJUNH6gEp9ZLi9l7WEA29ubHzxlsWC2gSSWDwpwjU+Cz OuT0ZYlPALb0akBXlCQ4TgqRcrYgFDcbxFqNUkzXvGOSZXASM2sPNN6DuOwZ8sPJXmW0 ZHPdEa5IBVi6iYnI1tacL1PNzdBRQ5npK9AvOGI2BKpG/GgiCWvd8a019hwXdP0wyjQg 7YfxFtZNfaCCJE6NmBPC38oAqpBoA/yzDnTizyMrRXpCLbAm9o8hiq86vwInnt/2Jx/F hlbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695653925; x=1696258725; 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=CEQieMP4Ciq9l3caJCpOqVvhgPb5r6CY0rRdq264kHpC4xt4kdioFhENG2Gqqmce23 cnXxO5MrwUuprocCTWbYwH159QH8Y4jNceWWGOZwBtCiS+Vx5ADeswslQwKdt5ypQXiB jTuNUbezO4S0PICNPS0yQ1NgI27bVnMj67qDiSayJIyXap0zsvcYJZBfJEcOUBTAyDmN MJxDQxAibvDyc2VzdEByRELm7lImmjjQFavLvV/hoEhjwndMmqfQ4SeT2XlWC02ILoPL +Mqk5V8QEkivU/ZqfZH8jC/xcW18yeHqBpNsyf1dVF3VCiyEkigGSPcaU2Kb+9+mrSQx ZhTg== X-Gm-Message-State: AOJu0YxfRgV4Jgf6xuIHZMlMfmyn/bFRsnxVospCC+gAOM7bzssB/w1R Fs+mGmYCdLV8cSQSCkJ5vVYn4Q== X-Received: by 2002:a05:600c:210a:b0:3fe:1cac:37d5 with SMTP id u10-20020a05600c210a00b003fe1cac37d5mr5768595wml.4.1695653925443; Mon, 25 Sep 2023 07:58:45 -0700 (PDT) Received: from zen.linaroharston ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id t1-20020a1c7701000000b003fe23b10fdfsm15367489wmi.36.2023.09.25.07.58.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 07:58:42 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id EC8801FFC2; Mon, 25 Sep 2023 15:48:57 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Alistair Francis , =?utf-8?q?C=C3=A9dric_Le_Go?= =?utf-8?q?ater?= , Marcin Juszkiewicz , John Snow , libvir-list@redhat.com, =?utf-8?q?Marc-Andr?= =?utf-8?q?=C3=A9_Lureau?= , qemu-s390x@nongnu.org, Song Gao , Daniel Henrique Barboza , Marcel Apfelbaum , Bastian Koppelmann , Liu Zhiwei , Weiwei Li , Nicholas Piggin , Radoslaw Biernacki , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Eduardo Habkost , Cleber Rosa , Paolo Bonzini , Mahmoud Mandour , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Thomas Huth , Wainer dos Santos Moschetta , Richard Henderson , Bin Meng , Alexandre Iooss , Xiaojuan Yang , qemu-ppc@nongnu.org, David Hildenbrand , =?utf-8?q?Alex_Benn=C3=A9e?= , Yanan Wang , Peter Maydell , qemu-riscv@nongnu.org, qemu-arm@nongnu.org, Palmer Dabbelt , Ilya Leoshkevich , Laurent Vivier , Yoshinori Sato , Leif Lindholm , Beraldo Leal Subject: [PATCH 24/31] contrib/plugins: fix coverity warning in cache Date: Mon, 25 Sep 2023 15:48:47 +0100 Message-Id: <20230925144854.1872513-25-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230925144854.1872513-1-alex.bennee@linaro.org> References: <20230925144854.1872513-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32f; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x32f.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=ham 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,