Skip to contentSkip to conversation

loader/efi/linux: Return correct size from LoadFile

PATCH Superseded Frediano Ziglio via Grub-devel 2 participants 3 messages Jul 14, 2025 – Jul 16, 2025

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 loader/efi/linux: Return correct size from LoadFile

From UEFI specifications 2.10, section 13.2.2,
"EFI_LOAD_FILE2_PROTOCOL.LoadFile" (see
https://uefi.org/specs/UEFI/2.10/13_Protocols_Media_Access.html),
for BufferSize:

On input the size of Buffer in bytes. On output with a return code of EFI_SUCCESS, the amount of data transferred to Buffer. On output with a return code of EFI_BUFFER_TOO_SMALL, the size of Buffer required to retrieve the requested file.

so set *buffer_size correctly.

---
Changes since v1:
- improved commit message

Changes since v2:
- return size only for EFI_SUCCESS.

---
 grub-core/loader/efi/linux.c | 2 ++
 1 file changed, 2 insertions(+)
grub-core/loader/efi/linux.c +2 -0
index 36dea2931..33415674c 100644
@@ -365,6 +365,8 @@ grub_efi_initrd_load_file2 (grub_efi_load_file2_t *this,
 
   if (grub_initrd_load (&initrd_ctx, buffer))
     status = GRUB_EFI_DEVICE_ERROR;
+  if (status == GRUB_EFI_SUCCESS)
+    *buffer_size = initrd_size;
 
   grub_initrd_close (&initrd_ctx);
   return status;
Signature · 7 lines
2.43.0


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
#1 lore raw
Quoted 28 lines · Frediano Ziglio via Grub-devel

From UEFI specifications 2.10, section 13.2.2,
"EFI_LOAD_FILE2_PROTOCOL.LoadFile" (see
https://uefi.org/specs/UEFI/2.10/13_Protocols_Media_Access.html),
for BufferSize:

On input the size of Buffer in bytes. On output with a return code of EFI_SUCCESS, the amount of data transferred to Buffer. On output with a return code of EFI_BUFFER_TOO_SMALL, the size of Buffer required to retrieve the requested file.

so set *buffer_size correctly.

---
Changes since v1:
- improved commit message

Changes since v2:
- return size only for EFI_SUCCESS.

---
 grub-core/loader/efi/linux.c | 2 ++
 1 file changed, 2 insertions(+)
grub-core/loader/efi/linux.c +0 -0
index 36dea2931..33415674c 100644

grub-core/loader/efi/linux.c grub_efi_initrd_load_file2 (grub_efi_load_file2_t *this, · line 368

Quoted 4 lines
grub-core/loader/efi/linux.c +1 -0
@@ -365,6 +365,8 @@ grub_efi_initrd_load_file2 (grub_efi_load_file2_t *this,
 
   if (grub_initrd_load (&initrd_ctx, buffer))
     status = GRUB_EFI_DEVICE_ERROR;
+  if (status == GRUB_EFI_SUCCESS)

"else" should be enough here...

grub-core/loader/efi/linux.c grub_efi_initrd_load_file2 (grub_efi_load_file2_t *this, · line 369

Quoted 1 line
grub-core/loader/efi/linux.c +1 -0
+    *buffer_size = initrd_size;

Daniel

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#2 lore raw
Quoted 31 lines · Daniel Kiper
Quoted 29 lines · Frediano Ziglio via Grub-devel

From UEFI specifications 2.10, section 13.2.2,
"EFI_LOAD_FILE2_PROTOCOL.LoadFile" (see
https://uefi.org/specs/UEFI/2.10/13_Protocols_Media_Access.html),
for BufferSize:

On input the size of Buffer in bytes. On output with a return code of EFI_SUCCESS, the amount of data transferred to Buffer. On output with a return code of EFI_BUFFER_TOO_SMALL, the size of Buffer required to retrieve the requested file.

so set *buffer_size correctly.

---
Changes since v1:
- improved commit message

Changes since v2:
- return size only for EFI_SUCCESS.

---
 grub-core/loader/efi/linux.c | 2 ++
 1 file changed, 2 insertions(+)
grub-core/loader/efi/linux.c +0 -0
index 36dea2931..33415674c 100644
@@ -365,6 +365,8 @@ grub_efi_initrd_load_file2 (grub_efi_load_file2_t *this,
 
Quoted 6 lines

grub-core/loader/efi/linux.c grub_efi_initrd_load_file2 (grub_efi_load_file2_t *this, · line 368

Quoted 3 lines
grub-core/loader/efi/linux.c +1 -0
   if (grub_initrd_load (&initrd_ctx, buffer))
     status = GRUB_EFI_DEVICE_ERROR;
+  if (status == GRUB_EFI_SUCCESS)

"else" should be enough here...

I'll do it

Quoted 3 lines

grub-core/loader/efi/linux.c grub_efi_initrd_load_file2 (grub_efi_load_file2_t *this, · line 369

Quoted 1 line
grub-core/loader/efi/linux.c +1 -0
+    *buffer_size = initrd_size;

Daniel

Frediano

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel