From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 3256B1A1DED for ; Thu, 27 Oct 2016 09:23:34 -0700 (PDT) Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 88748C057FA5; Thu, 27 Oct 2016 16:23:33 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-116-24.phx2.redhat.com [10.3.116.24]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u9RGNVkh016577; Thu, 27 Oct 2016 12:23:32 -0400 To: Gary Lin , edk2-devel@ml01.01.org References: <20161027101615.18247-1-glin@suse.com> Cc: Justen Jordan From: Laszlo Ersek Message-ID: Date: Thu, 27 Oct 2016 18:23:31 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: <20161027101615.18247-1-glin@suse.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Thu, 27 Oct 2016 16:23:33 +0000 (UTC) Subject: Re: [PATCH] OvmfPkg: Make use of ARRAY_SIZE() X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 27 Oct 2016 16:23:34 -0000 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit On 10/27/16 12:16, Gary Lin wrote: > Convert the remaining pieces to make the code shorter and more readable. > > Cc: Justen Jordan > Cc: Laszlo Ersek > Contributed-under: TianoCore Contribution Agreement 1.0 > Signed-off-by: Gary Lin > --- > OvmfPkg/Csm/CsmSupportLib/LegacyRegion.c | 8 ++++---- > OvmfPkg/Library/LoadLinuxLib/Linux.c | 2 +- > OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c | 4 +--- > OvmfPkg/VirtioGpuDxe/Gop.c | 7 +++---- > 4 files changed, 9 insertions(+), 12 deletions(-) > > diff --git a/OvmfPkg/Csm/CsmSupportLib/LegacyRegion.c b/OvmfPkg/Csm/CsmSupportLib/LegacyRegion.c > index b929db0..8d5d2e5 100644 > --- a/OvmfPkg/Csm/CsmSupportLib/LegacyRegion.c > +++ b/OvmfPkg/Csm/CsmSupportLib/LegacyRegion.c > @@ -130,18 +130,18 @@ LegacyRegionManipulationInternal ( > // Loop to find the start PAM. > // > StartIndex = 0; > - for (Index = 0; Index < (sizeof(mSectionArray) / sizeof (mSectionArray[0])); Index++) { > + for (Index = 0; Index < ARRAY_SIZE (mSectionArray); Index++) { > if ((Start >= mSectionArray[Index].Start) && (Start < (mSectionArray[Index].Start + mSectionArray[Index].Length))) { > StartIndex = Index; > break; > } > } > - ASSERT (Index < (sizeof(mSectionArray) / sizeof (mSectionArray[0]))); > + ASSERT (Index < ARRAY_SIZE (mSectionArray)); > > // > // Program PAM until end PAM is encountered > // > - for (Index = StartIndex; Index < (sizeof(mSectionArray) / sizeof (mSectionArray[0])); Index++) { > + for (Index = StartIndex; Index < ARRAY_SIZE (mSectionArray); Index++) { > if (ReadEnable != NULL) { > if (*ReadEnable) { > PciOr8 ( > @@ -177,7 +177,7 @@ LegacyRegionManipulationInternal ( > break; > } > } > - ASSERT (Index < (sizeof(mSectionArray) / sizeof (mSectionArray[0]))); > + ASSERT (Index < ARRAY_SIZE (mSectionArray)); > > return EFI_SUCCESS; > } > diff --git a/OvmfPkg/Library/LoadLinuxLib/Linux.c b/OvmfPkg/Library/LoadLinuxLib/Linux.c > index 9c996ad..68d1537 100644 > --- a/OvmfPkg/Library/LoadLinuxLib/Linux.c > +++ b/OvmfPkg/Library/LoadLinuxLib/Linux.c > @@ -357,7 +357,7 @@ SetupLinuxMemmap ( > LastE820->size += EFI_PAGES_TO_SIZE ((UINTN) MemoryMap->NumberOfPages); > LastEndAddr += EFI_PAGES_TO_SIZE ((UINTN) MemoryMap->NumberOfPages); > } else { > - if (E820EntryCount >= (sizeof (Bp->e820_map) / sizeof (Bp->e820_map[0]))) { > + if (E820EntryCount >= ARRAY_SIZE (Bp->e820_map)) { > break; > } > E820->type = (UINT32) E820Type; > diff --git a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c b/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c > index 6ba0ca6..ff83703 100644 > --- a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c > +++ b/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c > @@ -419,9 +419,7 @@ PciHostBridgeResourceConflict ( > DEBUG ((EFI_D_ERROR, "RootBridge[%d]:\n", RootBridgeIndex++)); > for (; Descriptor->Desc == ACPI_ADDRESS_SPACE_DESCRIPTOR; Descriptor++) { > ASSERT (Descriptor->ResType < > - (sizeof (mPciHostBridgeLibAcpiAddressSpaceTypeStr) / > - sizeof (mPciHostBridgeLibAcpiAddressSpaceTypeStr[0]) > - ) > + ARRAY_SIZE (mPciHostBridgeLibAcpiAddressSpaceTypeStr) > ); > DEBUG ((EFI_D_ERROR, " %s: Length/Alignment = 0x%lx / 0x%lx\n", > mPciHostBridgeLibAcpiAddressSpaceTypeStr[Descriptor->ResType], > diff --git a/OvmfPkg/VirtioGpuDxe/Gop.c b/OvmfPkg/VirtioGpuDxe/Gop.c > index c6ff9ed..3438bd0 100644 > --- a/OvmfPkg/VirtioGpuDxe/Gop.c > +++ b/OvmfPkg/VirtioGpuDxe/Gop.c > @@ -204,7 +204,7 @@ GopQueryMode ( > { > EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *GopModeInfo; > > - if (ModeNumber >= sizeof mGopResolutions / sizeof mGopResolutions[0]) { > + if (ModeNumber >= ARRAY_SIZE (mGopResolutions)) { > return EFI_INVALID_PARAMETER; > } > > @@ -239,7 +239,7 @@ GopSetMode ( > EFI_STATUS Status; > EFI_STATUS Status2; > > - if (ModeNumber >= sizeof mGopResolutions / sizeof mGopResolutions[0]) { > + if (ModeNumber >= ARRAY_SIZE (mGopResolutions)) { > return EFI_UNSUPPORTED; > } > > @@ -258,8 +258,7 @@ GopSetMode ( > // > VgpuGop->Gop.Mode = &VgpuGop->GopMode; > > - VgpuGop->GopMode.MaxMode = (UINT32)(sizeof mGopResolutions / > - sizeof mGopResolutions[0]); > + VgpuGop->GopMode.MaxMode = (UINT32)(ARRAY_SIZE (mGopResolutions)); > VgpuGop->GopMode.Info = &VgpuGop->GopModeInfo; > VgpuGop->GopMode.SizeOfInfo = sizeof VgpuGop->GopModeInfo; > > Reviewed-by: Laszlo Ersek [lersek@redhat.com: tweak subject line] Signed-off-by: Laszlo Ersek I changed the subject line like this: OvmfPkg: Make more use of ARRAY_SIZE() Commit 5a5025e485b2. Thanks! Laszlo