From nobody Tue Nov 26 12:41:50 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1707909802; cv=none; d=zohomail.com; s=zohoarc; b=abGNjoHBW9lhov44VTZKVgfc9lDroDP4K0OjqnveOY9ycajKL5fA3KeSuSmo84PTz1vUd7ByIcqvmhQiJR8uXqSuLr64g3+tTTTgJhuV43/iq8lcBBsIkDocO4vxzjrSq9fkVRL7yneSh3FMTn7DxG3bX7cidg+5YrAofWOkM10= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1707909802; h=Content-Type: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=uf4Q9wGfIlQGBzOLWZQCxpB+JmyuulvBhB/9UEzfO+A=; b=mFMT2nkNsyaQraJNWlKOxvXsqXIh5l2ZSIf20Vk/oopbnN311rOqoq181by5K8GcLMoliO+V8pSUxCL24Tv+WbnhRIkefNMfE8ZLt7yJC2pB+RnbT0kUCVANoRyRdP4hddhx/VwjIa8kBOkbqgmP5yyL2n1kjSBZEF98NFis9lI= 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 1707909802821742.9198080966969; Wed, 14 Feb 2024 03:23:22 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1raDFZ-0005vh-Gf; Wed, 14 Feb 2024 06:16:25 -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 1raDEw-00050O-5T for qemu-devel@nongnu.org; Wed, 14 Feb 2024 06:15:50 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1raDEu-0007Ho-Lw for qemu-devel@nongnu.org; Wed, 14 Feb 2024 06:15:45 -0500 Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-427-jOvTgSc6PjqmnAlFIVAwnQ-1; Wed, 14 Feb 2024 06:15:42 -0500 Received: by mail-ej1-f69.google.com with SMTP id a640c23a62f3a-a3d201e60f2so71831466b.3 for ; Wed, 14 Feb 2024 03:15:42 -0800 (PST) Received: from redhat.com ([2.52.26.67]) by smtp.gmail.com with ESMTPSA id ty8-20020a170907c70800b00a3d09d09e90sm1443404ejc.59.2024.02.14.03.15.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Feb 2024 03:15:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1707909344; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=uf4Q9wGfIlQGBzOLWZQCxpB+JmyuulvBhB/9UEzfO+A=; b=VEwUcy8McP5SFM3WubDM/vKGiMy/gjaj/Bzip+V/l2CJFDVgVmdLu4vMeS+GOu2LtWHLLl wKwm5pE7CWGmExO0mMZRCc2AoKy2lUFkMmBnKbGxeXxU3/K8lHiHqzuosDUKcGvXGRAffh y9c+eEAu/E3NPdPLGvJKnfo+xozH5r8= X-MC-Unique: jOvTgSc6PjqmnAlFIVAwnQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707909341; x=1708514141; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=uf4Q9wGfIlQGBzOLWZQCxpB+JmyuulvBhB/9UEzfO+A=; b=iHVIpQ8gjon7WciopQ2Az6q3LEZ/BNTZq2uY9/CuXF7OMAPpOvuGP12QdXCLWEcNum qx5P0TkoakT+h99vDRubiPjNJOkVqL7dFPZeVHNKTawKrrCtkhAeLyEctyCjAWJc0cUp 1GeaD82a2EvTHK0F56uyy7z9s0f4ZhI5ueDXoQjqi0jIQRjcNyiJ6Qb5ojSXlWuPALQv LTakKxV9U4KxWjxIFzoyU1TaZSEpUEgreIImmmcC3BrQ7gO2w4t+hOjsuWeRTZ/LBwcG V/ra/amQ0ePH9ptsgPuBgQnj1pJrUGsDSqwDpao3xb7uNpmm3tHDk8o1f0Wj2Jd+iOwt P8mA== X-Gm-Message-State: AOJu0YxTdUVDtCuq9jUWXQhzM9t6+8zrYHcp7Z/mfhxN0GZoHu8FkUEu MAV3e3GJjF5gFvOZrkjcE/CDGP89CrwjL1kt5SqRhtY8YtKmvwQWD4lF2ZPAYF4o/O28uW8CsVU 3IhsEgV/ImpYwqr8lIkTKRRf3hWYSqKYCoJmoKWETOH9kFsLAxe0Go+sFEpSkaswTxACXYutE3C CSyDewgQmSaROFBdWA9NhVwt+b/uirDA== X-Received: by 2002:a17:906:f6d4:b0:a3c:a3eb:4c10 with SMTP id jo20-20020a170906f6d400b00a3ca3eb4c10mr1628533ejb.63.1707909341154; Wed, 14 Feb 2024 03:15:41 -0800 (PST) X-Google-Smtp-Source: AGHT+IFkA372y6SW6ww4IR24mwEOdcitcIbp9DkhnB5BKYBCCmiLYACOWFnC1lsgJDd3lZWrofTPpQ== X-Received: by 2002:a17:906:f6d4:b0:a3c:a3eb:4c10 with SMTP id jo20-20020a170906f6d400b00a3ca3eb4c10mr1628516ejb.63.1707909340871; Wed, 14 Feb 2024 03:15:40 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCUFHPnSOA9eEWNPlYGqqJRpglthtcivzody29rPJAAxY5rjd6sJE947n6u2Mv435cCg4jXBxnawZwQlObMdSZcGFX03yAuRUrRXRM3iLN36wC6JaFPH5nNpX6RiHLiuok7nGNR4A4bnZtIM2xpylORn1Lcu Date: Wed, 14 Feb 2024 06:15:38 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Jonathan Cameron , Stefan Hajnoczi , Fan Ni Subject: [PULL 45/60] hw/mem/cxl_type3: Fix potential divide by zero reported by coverity Message-ID: <48461825af1bdc68cfa25fa0b698c958b65f7368.1707909001.git.mst@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent 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=170.10.129.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.504, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1707909804740100001 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Jonathan Cameron Fixes Coverity ID 1522368. Currently error_fatal is set if interleave_ways_dec() is going to return 0 but we should handle that zero return explicitly. Reported-by: Stefan Hajnoczi Reviewed-by: Fan Ni Signed-off-by: Jonathan Cameron Message-Id: <20240126120132.24248-10-Jonathan.Cameron@huawei.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/mem/cxl_type3.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/hw/mem/cxl_type3.c b/hw/mem/cxl_type3.c index 1b92a065a3..71fcb44613 100644 --- a/hw/mem/cxl_type3.c +++ b/hw/mem/cxl_type3.c @@ -794,8 +794,13 @@ static bool cxl_type3_dpa(CXLType3Dev *ct3d, hwaddr ho= st_addr, uint64_t *dpa) } if (((uint64_t)host_addr < decoder_base) || (hpa_offset >=3D decoder_size)) { - dpa_base +=3D decoder_size / - cxl_interleave_ways_dec(iw, &error_fatal); + int decoded_iw =3D cxl_interleave_ways_dec(iw, &error_fatal); + + if (decoded_iw =3D=3D 0) { + return false; + } + + dpa_base +=3D decoder_size / decoded_iw; continue; } =20 --=20 MST