From 58ace50a43097df8408d41aec81e4b47a5a79cfc Mon Sep 17 00:00:00 2001 From: Michael Kubacki Date: Tue, 3 Feb 2026 13:28:42 -0500 Subject: [PATCH] FmpDevicePkg: Replace include guards with #pragma once Replace traditional `#ifndef`/`#define`/`#endif` include guards with `#pragma` once. `#pragma once` is a widely supported preprocessor directive that prevents header files from being included multiple times. It is supported by all toolchains used to build edk2: GCC, Clang/LLVM, and MSVC. Compared to macro-based include guards, `#pragma once`: - Eliminates the risk of macro name collisions or copy/paste errors where two headers inadvertently use the same guard macro. - Eliminate inconsistency in the way include guard macros are named (e.g., some files use `__FILE_H__`, others use `FILE_H_`, etc.). - Reduces boilerplate (three lines replaced by one). - Avoids polluting the macro namespace with guard symbols. - Can improve build times as the preprocessor can skip re-opening the file entirely, rather than re-reading it to find the matching `#endif` ("multiple-include optimization"). - Note that some compilers may already optimize traditional include guards, by recognzining the idiomatic pattern. This change is made acknowledging that overall portability of the code will technically be reduced, as `#pragma once` is not part of the C/C++ standards. However, this is considered acceptable given: 1. edk2 already defines a subset of supported compilers in BaseTools/Conf/tools_def.template, all of which have supported `#pragma once` for over two decades. 2. There have been concerns raised to the project about inconsistent include guard naming and potential macro collisions. Approximate compiler support dates: - MSVC: Supported since Visual C++ 4.2 (1996) - GCC: Supported since 3.4 (2004) (http://gnu.ist.utl.pt/software/gcc/gcc-3.4/changes.html) - Clang (LLVM based): Since initial release in 2007 Signed-off-by: Michael Kubacki --- FmpDevicePkg/CapsuleUpdatePolicyDxe/CapsuleUpdatePolicyDxe.h | 5 +---- FmpDevicePkg/FmpDxe/FmpDxe.h | 5 +---- FmpDevicePkg/FmpDxe/VariableSupport.h | 5 +---- FmpDevicePkg/Include/LastAttemptStatus.h | 5 +---- FmpDevicePkg/Include/Library/CapsuleUpdatePolicyLib.h | 5 +---- FmpDevicePkg/Include/Library/FmpDependencyCheckLib.h | 5 +---- FmpDevicePkg/Include/Library/FmpDependencyDeviceLib.h | 5 +---- FmpDevicePkg/Include/Library/FmpDependencyLib.h | 5 +---- FmpDevicePkg/Include/Library/FmpDeviceLib.h | 5 +---- FmpDevicePkg/PrivateInclude/FmpLastAttemptStatus.h | 5 +---- FmpDevicePkg/PrivateInclude/Library/FmpPayloadHeaderLib.h | 5 +---- FmpDevicePkg/PrivateInclude/Protocol/CapsuleUpdatePolicy.h | 5 +---- 12 files changed, 12 insertions(+), 48 deletions(-) diff --git a/FmpDevicePkg/CapsuleUpdatePolicyDxe/CapsuleUpdatePolicyDxe.h b/FmpDevicePkg/CapsuleUpdatePolicyDxe/CapsuleUpdatePolicyDxe.h index 1be15a40db..cfdb60259e 100644 --- a/FmpDevicePkg/CapsuleUpdatePolicyDxe/CapsuleUpdatePolicyDxe.h +++ b/FmpDevicePkg/CapsuleUpdatePolicyDxe/CapsuleUpdatePolicyDxe.h @@ -8,8 +8,7 @@ **/ -#ifndef __CAPSULE_UPDATE_POLICY_DXE_H__ -#define __CAPSULE_UPDATE_POLICY_DXE_H__ +#pragma once #include @@ -136,5 +135,3 @@ CapsuleUpdatePolicyInitialize ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ); - -#endif diff --git a/FmpDevicePkg/FmpDxe/FmpDxe.h b/FmpDevicePkg/FmpDxe/FmpDxe.h index 5b1d442238..c23b1b9d8a 100644 --- a/FmpDevicePkg/FmpDxe/FmpDxe.h +++ b/FmpDevicePkg/FmpDxe/FmpDxe.h @@ -10,8 +10,7 @@ **/ -#ifndef _FMP_DXE_H_ -#define _FMP_DXE_H_ +#pragma once #include #include @@ -365,5 +364,3 @@ SetPackageInfo ( IN UINT32 PackageVersion, IN CONST CHAR16 *PackageVersionName ); - -#endif diff --git a/FmpDevicePkg/FmpDxe/VariableSupport.h b/FmpDevicePkg/FmpDxe/VariableSupport.h index f23ab11d69..516e799fca 100644 --- a/FmpDevicePkg/FmpDxe/VariableSupport.h +++ b/FmpDevicePkg/FmpDxe/VariableSupport.h @@ -9,8 +9,7 @@ **/ -#ifndef __VARIABLE_SUPPORT_H__ -#define __VARIABLE_SUPPORT_H__ +#pragma once /// /// Default values for FMP Controller State information @@ -234,5 +233,3 @@ EFI_STATUS LockAllFmpVariables ( IN FIRMWARE_MANAGEMENT_PRIVATE_DATA *Private ); - -#endif diff --git a/FmpDevicePkg/Include/LastAttemptStatus.h b/FmpDevicePkg/Include/LastAttemptStatus.h index 4a81d2737b..d7c6c1a08a 100644 --- a/FmpDevicePkg/Include/LastAttemptStatus.h +++ b/FmpDevicePkg/Include/LastAttemptStatus.h @@ -8,8 +8,7 @@ **/ -#ifndef __LAST_ATTEMPT_STATUS_H__ -#define __LAST_ATTEMPT_STATUS_H__ +#pragma once /// /// Last Attempt Status Unsuccessful Vendor Range Map @@ -77,5 +76,3 @@ /// The maximum value allowed for FMP device library errors. /// #define LAST_ATTEMPT_STATUS_DEVICE_LIBRARY_MAX_ERROR_CODE_VALUE 0x1FFF - -#endif diff --git a/FmpDevicePkg/Include/Library/CapsuleUpdatePolicyLib.h b/FmpDevicePkg/Include/Library/CapsuleUpdatePolicyLib.h index fa0406029c..bd3a3a9d1d 100644 --- a/FmpDevicePkg/Include/Library/CapsuleUpdatePolicyLib.h +++ b/FmpDevicePkg/Include/Library/CapsuleUpdatePolicyLib.h @@ -8,8 +8,7 @@ **/ -#ifndef __CAPSULE_UPDATE_POLICY_LIB__ -#define __CAPSULE_UPDATE_POLICY_LIB__ +#pragma once /** Determine if the system power state supports a capsule update. @@ -99,5 +98,3 @@ EFIAPI IsLockFmpDeviceAtLockEventGuidRequired ( VOID ); - -#endif diff --git a/FmpDevicePkg/Include/Library/FmpDependencyCheckLib.h b/FmpDevicePkg/Include/Library/FmpDependencyCheckLib.h index d8962c426a..65cb5840df 100644 --- a/FmpDevicePkg/Include/Library/FmpDependencyCheckLib.h +++ b/FmpDevicePkg/Include/Library/FmpDependencyCheckLib.h @@ -9,8 +9,7 @@ **/ -#ifndef __FMP_DEPENDENCY_CHECK_LIB__ -#define __FMP_DEPENDENCY_CHECK_LIB__ +#pragma once #include #include @@ -40,5 +39,3 @@ CheckFmpDependency ( IN UINT32 DependenciesSize, OUT UINT32 *LastAttemptStatus OPTIONAL ); - -#endif diff --git a/FmpDevicePkg/Include/Library/FmpDependencyDeviceLib.h b/FmpDevicePkg/Include/Library/FmpDependencyDeviceLib.h index 173e415b6f..8f28f6b92f 100644 --- a/FmpDevicePkg/Include/Library/FmpDependencyDeviceLib.h +++ b/FmpDevicePkg/Include/Library/FmpDependencyDeviceLib.h @@ -8,8 +8,7 @@ **/ -#ifndef __FMP_DEPENDENCY_DEVICE_LIB__ -#define __FMP_DEPENDENCY_DEVICE_LIB__ +#pragma once #include #include @@ -47,5 +46,3 @@ EFIAPI GetFmpDependency ( OUT UINT32 *DepexSize ); - -#endif diff --git a/FmpDevicePkg/Include/Library/FmpDependencyLib.h b/FmpDevicePkg/Include/Library/FmpDependencyLib.h index a1f577272b..5cdfb940d3 100644 --- a/FmpDevicePkg/Include/Library/FmpDependencyLib.h +++ b/FmpDevicePkg/Include/Library/FmpDependencyLib.h @@ -9,8 +9,7 @@ **/ -#ifndef __FMP_DEPENDENCY_LIB__ -#define __FMP_DEPENDENCY_LIB__ +#pragma once #include #include @@ -100,5 +99,3 @@ EvaluateDependency ( IN UINTN FmpVersionsCount, OUT UINT32 *LastAttemptStatus OPTIONAL ); - -#endif diff --git a/FmpDevicePkg/Include/Library/FmpDeviceLib.h b/FmpDevicePkg/Include/Library/FmpDeviceLib.h index f82ef64503..4b3c6e2370 100644 --- a/FmpDevicePkg/Include/Library/FmpDeviceLib.h +++ b/FmpDevicePkg/Include/Library/FmpDeviceLib.h @@ -9,8 +9,7 @@ **/ -#ifndef __FMP_DEVICE_LIB__ -#define __FMP_DEVICE_LIB__ +#pragma once #include @@ -604,5 +603,3 @@ EFIAPI FmpDeviceLock ( VOID ); - -#endif diff --git a/FmpDevicePkg/PrivateInclude/FmpLastAttemptStatus.h b/FmpDevicePkg/PrivateInclude/FmpLastAttemptStatus.h index aaa3334909..f13d3bf35f 100644 --- a/FmpDevicePkg/PrivateInclude/FmpLastAttemptStatus.h +++ b/FmpDevicePkg/PrivateInclude/FmpLastAttemptStatus.h @@ -7,8 +7,7 @@ **/ -#ifndef __FMP_LAST_ATTEMPT_STATUS_H__ -#define __FMP_LAST_ATTEMPT_STATUS_H__ +#pragma once /// /// Last attempt status codes defined for additional granularity in FmpDevicePkg components. @@ -79,5 +78,3 @@ enum LAST_ATTEMPT_STATUS_EXPANDED_ERROR_LIST { LAST_ATTEMPT_STATUS_DEPENDENCY_CHECK_LIB_ERROR_MEM_ALLOC_DESC_SIZE_BUFFER_FAILED, LAST_ATTEMPT_STATUS_DEPENDENCY_CHECK_LIB_ERROR_MEM_ALLOC_FMP_VER_BUFFER_FAILED }; - -#endif diff --git a/FmpDevicePkg/PrivateInclude/Library/FmpPayloadHeaderLib.h b/FmpDevicePkg/PrivateInclude/Library/FmpPayloadHeaderLib.h index a527c82460..9665210c75 100644 --- a/FmpDevicePkg/PrivateInclude/Library/FmpPayloadHeaderLib.h +++ b/FmpDevicePkg/PrivateInclude/Library/FmpPayloadHeaderLib.h @@ -12,8 +12,7 @@ **/ -#ifndef _FMP_PAYLOAD_HEADER_LIB_H__ -#define _FMP_PAYLOAD_HEADER_LIB_H__ +#pragma once /** Returns the FMP Payload Header size in bytes. @@ -79,5 +78,3 @@ GetFmpPayloadHeaderLowestSupportedVersion ( IN CONST UINTN FmpPayloadSize, OUT UINT32 *LowestSupportedVersion ); - -#endif diff --git a/FmpDevicePkg/PrivateInclude/Protocol/CapsuleUpdatePolicy.h b/FmpDevicePkg/PrivateInclude/Protocol/CapsuleUpdatePolicy.h index 7292f8e31b..1b6757a448 100644 --- a/FmpDevicePkg/PrivateInclude/Protocol/CapsuleUpdatePolicy.h +++ b/FmpDevicePkg/PrivateInclude/Protocol/CapsuleUpdatePolicy.h @@ -7,8 +7,7 @@ **/ -#ifndef __CAPSULE_UPDATE_POLICY_H__ -#define __CAPSULE_UPDATE_POLICY_H__ +#pragma once #define EDKII_CAPSULE_UPDATE_POLICY_PROTOCOL_GUID \ { \ @@ -128,5 +127,3 @@ struct _EDKII_CAPSULE_UPDATE_POLICY_PROTOCOL { }; extern EFI_GUID gEdkiiCapsuleUpdatePolicyProtocolGuid; - -#endif