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 3EB5DD8100D for ; Thu, 9 Nov 2023 17:39:23 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=Y3DUueWoVCKhpwiRBX6u6wvIQaalwMWlEreVVxsJErw=; 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=1699551561; v=1; b=aou4ZAdHE+39QPYp01/G4k3umrkobimglPsIaXOu7yMESTok7o7+UrPKvyPc7NirV/lMXf1V DyBTx8fZRKX2qm2mozpQrUrrg+y94YfKzZ1hP650iZLKaa79LIEFOklsmVf9IjiPCtwUbsnruUs KjlZR84axQ3KKMyNapOVIJio= X-Received: by 127.0.0.2 with SMTP id A3gnYY7687511xEUBM84Etkc; Thu, 09 Nov 2023 09:39:21 -0800 X-Received: from mail-il1-f176.google.com (mail-il1-f176.google.com [209.85.166.176]) by mx.groups.io with SMTP id smtpd.web11.207.1699551561343834131 for ; Thu, 09 Nov 2023 09:39:21 -0800 X-Received: by mail-il1-f176.google.com with SMTP id e9e14a558f8ab-359c1f42680so4173845ab.2 for ; Thu, 09 Nov 2023 09:39:21 -0800 (PST) X-Gm-Message-State: 7FMqvHrFJEaXWz7lGuVskfpbx7686176AA= X-Google-Smtp-Source: AGHT+IECx5KhpX6nkbrraSV1gy8gP+VNf3gGcRx5NNt6nsGDSAjD5lGHcOJ1Og47BAiknKuOcY7TYw== X-Received: by 2002:a05:6e02:20c3:b0:357:a640:3235 with SMTP id 3-20020a056e0220c300b00357a6403235mr7271388ilq.29.1699551560312; Thu, 09 Nov 2023 09:39:20 -0800 (PST) X-Received: from user-Latitude-5420.dc1.ventanamicro.com ([2401:4900:1f24:28fe:87c2:d0fc:f722:4f0d]) by smtp.gmail.com with ESMTPSA id ei14-20020a05663829ae00b0045c1fcf2ef7sm3876355jab.37.2023.11.09.09.39.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Nov 2023 09:39:20 -0800 (PST) From: "Ranbir Singh" To: devel@edk2.groups.io, rsingh@ventanamicro.com Cc: Ray Ni Subject: [edk2-devel] [PATCH v3 2/2] MdeModulePkg/Bus/Pci/PciHostBridgeDxe: Fix MISSING_BREAK Coverity issue Date: Thu, 9 Nov 2023 23:09:07 +0530 Message-Id: <20231109173908.364630-3-rsingh@ventanamicro.com> In-Reply-To: <20231109173908.364630-1-rsingh@ventanamicro.com> References: <20231109173908.364630-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=aou4ZAdH; spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io; dmarc=none From: Ranbir Singh The function SubmitResources has a switch-case code in which the case ACPI_ADDRESS_SPACE_TYPE_MEM: which falls through to case ACPI_ADDRESS_SPACE_TYPE_IO: to include additional common check. While this may be intentional, it may not be evident to any general code reader/developer or static analyis tool why there is no break in between. SubmitResources function is supposed to handle only Mem or IO resources. So, update the ResType parameter check reflecting that and re-model the switch-case code in contention using just one if condition to further handle other parameter checks specific to ACPI_ADDRESS_SPACE_TYPE_MEM. This leads to mostly indentation level code changes. Few ASSERT's later present are henceforth not required. REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4212 Cc: Ray Ni Signed-off-by: Ranbir Singh --- MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridge.c | 60 +++++++++------= ----- 1 file changed, 26 insertions(+), 34 deletions(-) diff --git a/MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridge.c b/MdeMod= ulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridge.c index c2c143068cd2..ed0aa455bfd4 100644 --- a/MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridge.c +++ b/MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridge.c @@ -1453,7 +1453,7 @@ SetBusNumbers ( Submits the I/O and memory resource requirements for the specified PCI R= oot Bridge.=0D =0D @param This The EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_ PR= OTOCOL instance.=0D - @param RootBridgeHandle The PCI Root Bridge whose I/O and memory resour= ce requirements.=0D + @param RootBridgeHandle The PCI Root Bridge whose I/O and memory resour= ce requirements=0D are being submitted.=0D @param Configuration The pointer to the PCI I/O and PCI memory resou= rce descriptor.=0D =0D @@ -1496,7 +1496,7 @@ SubmitResources ( // descriptors are ignored and the function returns EFI_INVALID_PARA= METER.=0D //=0D for (Descriptor =3D (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *)Configurati= on; Descriptor->Desc =3D=3D ACPI_ADDRESS_SPACE_DESCRIPTOR; Descriptor++) {= =0D - if (Descriptor->ResType > ACPI_ADDRESS_SPACE_TYPE_BUS) {=0D + if ((Descriptor->ResType !=3D ACPI_ADDRESS_SPACE_TYPE_MEM) && (Des= criptor->ResType !=3D ACPI_ADDRESS_SPACE_TYPE_IO)) {=0D return EFI_INVALID_PARAMETER;=0D }=0D =0D @@ -1509,40 +1509,34 @@ SubmitResources ( (Descriptor->SpecificFlag & EFI_ACPI_MEMORY_RESOURCE_SPECIFIC_FL= AG_CACHEABLE_PREFETCHABLE) !=3D 0 ? L" (Prefetchable)" : L""=0D ));=0D DEBUG ((DEBUG_INFO, " Length/Alignment =3D 0x%lx / 0x%lx\n", = Descriptor->AddrLen, Descriptor->AddrRangeMax));=0D - switch (Descriptor->ResType) {=0D - case ACPI_ADDRESS_SPACE_TYPE_MEM:=0D - if ((Descriptor->AddrSpaceGranularity !=3D 32) && (Descriptor-= >AddrSpaceGranularity !=3D 64)) {=0D - return EFI_INVALID_PARAMETER;=0D - }=0D =0D - if ((Descriptor->AddrSpaceGranularity =3D=3D 32) && (Descripto= r->AddrLen >=3D SIZE_4GB)) {=0D - return EFI_INVALID_PARAMETER;=0D - }=0D + if (Descriptor->ResType =3D=3D ACPI_ADDRESS_SPACE_TYPE_MEM) {=0D + if ((Descriptor->AddrSpaceGranularity !=3D 32) && (Descriptor->A= ddrSpaceGranularity !=3D 64)) {=0D + return EFI_INVALID_PARAMETER;=0D + }=0D =0D - //=0D - // If the PCI root bridge does not support separate windows fo= r nonprefetchable and=0D - // prefetchable memory, then the PCI bus driver needs to inclu= de requests for=0D - // prefetchable memory in the nonprefetchable memory pool.=0D - //=0D - if (((RootBridge->AllocationAttributes & EFI_PCI_HOST_BRIDGE_C= OMBINE_MEM_PMEM) !=3D 0) &&=0D - ((Descriptor->SpecificFlag & EFI_ACPI_MEMORY_RESOURCE_SPEC= IFIC_FLAG_CACHEABLE_PREFETCHABLE) !=3D 0)=0D - )=0D - {=0D - return EFI_INVALID_PARAMETER;=0D - }=0D + if ((Descriptor->AddrSpaceGranularity =3D=3D 32) && (Descriptor-= >AddrLen >=3D SIZE_4GB)) {=0D + return EFI_INVALID_PARAMETER;=0D + }=0D =0D - case ACPI_ADDRESS_SPACE_TYPE_IO:=0D - //=0D - // Check aligment, it should be of the form 2^n-1=0D - //=0D - if (GetPowerOfTwo64 (Descriptor->AddrRangeMax + 1) !=3D (Descr= iptor->AddrRangeMax + 1)) {=0D - return EFI_INVALID_PARAMETER;=0D - }=0D + //=0D + // If the PCI root bridge does not support separate windows for = nonprefetchable and=0D + // prefetchable memory, then the PCI bus driver needs to include= requests for=0D + // prefetchable memory in the nonprefetchable memory pool.=0D + //=0D + if (((RootBridge->AllocationAttributes & EFI_PCI_HOST_BRIDGE_COM= BINE_MEM_PMEM) !=3D 0) &&=0D + ((Descriptor->SpecificFlag & EFI_ACPI_MEMORY_RESOURCE_SPECIF= IC_FLAG_CACHEABLE_PREFETCHABLE) !=3D 0)=0D + )=0D + {=0D + return EFI_INVALID_PARAMETER;=0D + }=0D + }=0D =0D - break;=0D - default:=0D - ASSERT (FALSE);=0D - break;=0D + //=0D + // Check aligment, it should be of the form 2^n-1=0D + //=0D + if (GetPowerOfTwo64 (Descriptor->AddrRangeMax + 1) !=3D (Descripto= r->AddrRangeMax + 1)) {=0D + return EFI_INVALID_PARAMETER;=0D }=0D }=0D =0D @@ -1559,7 +1553,6 @@ SubmitResources ( Type =3D TypeMem32;=0D }=0D } else {=0D - ASSERT (Descriptor->AddrSpaceGranularity =3D=3D 64);=0D if ((Descriptor->SpecificFlag & EFI_ACPI_MEMORY_RESOURCE_SPECI= FIC_FLAG_CACHEABLE_PREFETCHABLE) !=3D 0) {=0D Type =3D TypePMem64;=0D } else {=0D @@ -1567,7 +1560,6 @@ SubmitResources ( }=0D }=0D } else {=0D - ASSERT (Descriptor->ResType =3D=3D ACPI_ADDRESS_SPACE_TYPE_IO);= =0D Type =3D TypeIo;=0D }=0D =0D --=20 2.34.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#110994): https://edk2.groups.io/g/devel/message/110994 Mute This Topic: https://groups.io/mt/102490514/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-