From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by spool.mail.gandi.net (Postfix) with ESMTPS id 0A783740037 for ; Wed, 27 Sep 2023 06:17:16 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=rZEm/pFnll0ew/lyaLrFftI7hpnNYPEXOnLrNwUXRkY=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1695795435; v=1; b=MsuZ14HuzUjJCAvZIOr6mxGRWO8JPB8kItxGsWJyCCmRgishSi5NDk5V8brbgWGWNfAwx1dr xx6gbzvXhkXsQE7jLk5ywf4TlwVwieISSVVOpx/kYKxZOhuaskZ44iYO1h+Xx70/PnDnlAFLj+G rfAftp2NNhTa5HGL3aAYo2O0= X-Received: by 127.0.0.2 with SMTP id 7T4cYY7687511xZWkKrfNhbW; Tue, 26 Sep 2023 23:17:15 -0700 X-Received: from mail-io1-f51.google.com (mail-io1-f51.google.com [209.85.166.51]) by mx.groups.io with SMTP id smtpd.web11.11919.1695795434958660080 for ; Tue, 26 Sep 2023 23:17:15 -0700 X-Received: by mail-io1-f51.google.com with SMTP id ca18e2360f4ac-79f989480e0so326553339f.3 for ; Tue, 26 Sep 2023 23:17:14 -0700 (PDT) X-Gm-Message-State: tLKUWacMfl6olQ4bIco3woZWx7686176AA= X-Google-Smtp-Source: AGHT+IGEQahJ3ZlAC0xy7CQUR4xZpj/p1cvY5pTmsHUE+K7hyutBZEiX0OsAIS24nSgRwKPxmafmUQ== X-Received: by 2002:a6b:5b1a:0:b0:787:1472:3181 with SMTP id v26-20020a6b5b1a000000b0078714723181mr1274147ioh.3.1695795434012; Tue, 26 Sep 2023 23:17:14 -0700 (PDT) X-Received: from user-Latitude-5420.dc1.ventanamicro.com ([106.51.83.242]) by smtp.gmail.com with ESMTPSA id o23-20020a6b5a17000000b007836c7e8dccsm2571625iob.17.2023.09.26.23.17.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Sep 2023 23:17:13 -0700 (PDT) From: "Ranbir Singh" To: devel@edk2.groups.io, rsingh@ventanamicro.com Cc: Hao A Wu , Ray Ni , Veeresh Sangolli Subject: [edk2-devel] [PATCH v1 3/5] MdeModulePkg/Bus/Pci/PciBusDxe: Fix ARRAY_VS_SINGLETON Coverity issues Date: Wed, 27 Sep 2023 11:46:59 +0530 Message-Id: <20230927061701.451202-4-rsingh@ventanamicro.com> In-Reply-To: <20230927061701.451202-1-rsingh@ventanamicro.com> References: <20230927061701.451202-1-rsingh@ventanamicro.com> MIME-Version: 1.0 Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,rsingh@ventanamicro.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: Content-Transfer-Encoding: quoted-printable X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=MsuZ14Hu; dmarc=none; spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io From: Ranbir Singh The function PciHostBridgeResourceAllocator is not making use of the generic approach as is used in one of the other function namely - DumpResourceMap. As a result, the following warnings can be seen as reported by Coverity e.g. (30) Event address_of: Taking address with "&IoBridge" yields a singleton pointer. (31) Event callee_ptr_arith: Passing "&IoBridge" to function "FindResourceNode" which uses it as an array. This might corrupt or misinterpret adjacent memory locations. Hence, adopt the generic approach to fix the issues at relevant points. REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4239 Cc: Hao A Wu Cc: Ray Ni Co-authored-by: Veeresh Sangolli Signed-off-by: Ranbir Singh Signed-off-by: Ranbir Singh --- MdeModulePkg/Bus/Pci/PciBusDxe/PciLib.c | 37 ++++++++++++++++---- 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/MdeModulePkg/Bus/Pci/PciBusDxe/PciLib.c b/MdeModulePkg/Bus/Pci= /PciBusDxe/PciLib.c index 84fc0161a19c..71767d3793d4 100644 --- a/MdeModulePkg/Bus/Pci/PciBusDxe/PciLib.c +++ b/MdeModulePkg/Bus/Pci/PciBusDxe/PciLib.c @@ -485,6 +485,8 @@ PciHostBridgeResourceAllocator ( UINT64 Mem64ResStatus;=0D UINT64 PMem64ResStatus;=0D UINT32 MaxOptionRomSize;=0D + PCI_RESOURCE_NODE **ChildResources;=0D + UINTN ChildResourceCount;=0D PCI_RESOURCE_NODE *IoBridge;=0D PCI_RESOURCE_NODE *Mem32Bridge;=0D PCI_RESOURCE_NODE *PMem32Bridge;=0D @@ -895,16 +897,39 @@ PciHostBridgeResourceAllocator ( // Create the entire system resource map from the information collecte= d by=0D // enumerator. Several resource tree was created=0D //=0D - FindResourceNode (RootBridgeDev, &IoPool, &IoBridge);=0D - FindResourceNode (RootBridgeDev, &Mem32Pool, &Mem32Bridge);=0D - FindResourceNode (RootBridgeDev, &PMem32Pool, &PMem32Bridge);=0D - FindResourceNode (RootBridgeDev, &Mem64Pool, &Mem64Bridge);=0D - FindResourceNode (RootBridgeDev, &PMem64Pool, &PMem64Bridge);=0D -=0D + ChildResourceCount =3D FindResourceNode (RootBridgeDev, &IoPool, NULL)= ;=0D + ChildResources =3D AllocatePool (sizeof (PCI_RESOURCE_NODE *) * ChildR= esourceCount);=0D + ASSERT (ChildResources !=3D NULL);=0D + FindResourceNode (RootBridgeDev, &IoPool, &ChildResources[0]);=0D + IoBridge =3D ChildResources[0];=0D ASSERT (IoBridge !=3D NULL);=0D +=0D + ChildResourceCount =3D FindResourceNode (RootBridgeDev, &Mem32Pool, NU= LL);=0D + ChildResources =3D AllocatePool (sizeof (PCI_RESOURCE_NODE *) * ChildR= esourceCount);=0D + ASSERT (ChildResources !=3D NULL);=0D + FindResourceNode (RootBridgeDev, &Mem32Pool, &ChildResources[0]);=0D + Mem32Bridge =3D ChildResources[0];=0D ASSERT (Mem32Bridge !=3D NULL);=0D +=0D + ChildResourceCount =3D FindResourceNode (RootBridgeDev, &PMem32Pool, N= ULL);=0D + ChildResources =3D AllocatePool (sizeof (PCI_RESOURCE_NODE *) * ChildR= esourceCount);=0D + ASSERT (ChildResources !=3D NULL);=0D + FindResourceNode (RootBridgeDev, &PMem32Pool, &ChildResources[0]);=0D + PMem32Bridge =3D ChildResources[0];=0D ASSERT (PMem32Bridge !=3D NULL);=0D +=0D + ChildResourceCount =3D FindResourceNode (RootBridgeDev, &Mem64Pool, NU= LL);=0D + ChildResources =3D AllocatePool (sizeof (PCI_RESOURCE_NODE *) * ChildR= esourceCount);=0D + ASSERT (ChildResources !=3D NULL);=0D + FindResourceNode (RootBridgeDev, &Mem64Pool, &ChildResources[0]);=0D + Mem64Bridge =3D ChildResources[0];=0D ASSERT (Mem64Bridge !=3D NULL);=0D +=0D + ChildResourceCount =3D FindResourceNode (RootBridgeDev, &PMem64Pool, N= ULL);=0D + ChildResources =3D AllocatePool (sizeof (PCI_RESOURCE_NODE *) * ChildR= esourceCount);=0D + ASSERT (ChildResources !=3D NULL);=0D + FindResourceNode (RootBridgeDev, &PMem64Pool, &ChildResources[0]);=0D + PMem64Bridge =3D ChildResources[0];=0D ASSERT (PMem64Bridge !=3D NULL);=0D =0D //=0D --=20 2.34.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#109110): https://edk2.groups.io/g/devel/message/109110 Mute This Topic: https://groups.io/mt/101612809/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-