From 76132a56892aa3178697d958991ac4d129cb7042 Mon Sep 17 00:00:00 2001 From: Mingjie Shen Date: Mon, 31 Aug 2026 18:14:24 -0400 Subject: OvmfPkg/LoongArchVirt: Use FFS_FILE_SIZE to read FFS file size Replace the open-coded read of the 3-byte FFS file Size[] field in FindFfsFileAndSection() with the FFS_FILE_SIZE() macro from Pi/PiFirmwareFile.h. The macro reads exactly the three Size[] bytes (endianness-safe) instead of a 4-byte load that over-reads the adjacent byte. No functional change. Verified by building the module for LOONGARCH64 with a GCC cross toolchain: build -p OvmfPkg/LoongArchVirt/LoongArchVirtQemu.dsc -a LOONGARCH64 \ -t GCC -b DEBUG -m OvmfPkg/LoongArchVirt/Sec/SecMain.inf SecMain.c compiles and links into SecMain.efi. Generated with the following Coccinelle semantic patch: ```smpl @@ EFI_FFS_FILE_HEADER *E; typedef UINT32; @@ ( - *(UINT32 *)(E->Size) & 0x00FFFFFF + FFS_FILE_SIZE (E) | - *(UINT32 *)E->Size & 0x00FFFFFF + FFS_FILE_SIZE (E) ) ``` Signed-off-by: Mingjie Shen --- OvmfPkg/LoongArchVirt/Sec/SecMain.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OvmfPkg/LoongArchVirt/Sec/SecMain.c b/OvmfPkg/LoongArchVirt/Sec/SecMain.c index 6f541b1b89..10df18f3fd 100644 --- a/OvmfPkg/LoongArchVirt/Sec/SecMain.c +++ b/OvmfPkg/LoongArchVirt/Sec/SecMain.c @@ -207,7 +207,7 @@ FindFfsFileAndSection ( } File = (EFI_FFS_FILE_HEADER *)(UINTN)CurrentAddress; - Size = *(UINT32 *)File->Size & 0xffffff; + Size = FFS_FILE_SIZE (File); if (Size < (sizeof (*File) + sizeof (EFI_COMMON_SECTION_HEADER))) { return EFI_VOLUME_CORRUPTED; } -- cgit v1.2.3