diff mbox series

[v3,1/2] hw/core/loader: Use ssize_t for efi zboot unpacker

Message ID 20250102-la-direct-kernel-boot-v3-1-40dbc45d633a@flygoat.com (mailing list archive)
State New
Headers show
Series hw/loongarch/boot: Support Linux raw boot image | expand

Commit Message

Jiaxun Yang Jan. 2, 2025, 10:47 p.m. UTC
Convert to use sszie_t to represent size internally to avoid
large image overflowing the size.

Suggested-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
---
 hw/arm/boot.c       | 2 +-
 hw/core/loader.c    | 4 ++--
 include/hw/loader.h | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/hw/arm/boot.c b/hw/arm/boot.c
index 5301d8d318cabae63be5f58c3179b49b187f2512..d780c36c47378aebf4e7484c895085e25dd640e6 100644
--- a/hw/arm/boot.c
+++ b/hw/arm/boot.c
@@ -857,7 +857,7 @@  static uint64_t load_aarch64_image(const char *filename, hwaddr mem_base,
     hwaddr kernel_load_offset = KERNEL64_LOAD_ADDR;
     uint64_t kernel_size = 0;
     uint8_t *buffer;
-    int size;
+    ssize_t size;
 
     /* On aarch64, it's the bootloader's job to uncompress the kernel. */
     size = load_image_gzipped_buffer(filename, LOAD_IMAGE_MAX_GUNZIP_BYTES,
diff --git a/hw/core/loader.c b/hw/core/loader.c
index 31593a117171a30dec68c2b8141ba99834e5363d..11b5813f4664f0a825147bb637a0b9fef21625e4 100644
--- a/hw/core/loader.c
+++ b/hw/core/loader.c
@@ -886,11 +886,11 @@  struct linux_efi_zboot_header {
  *
  * If the image is not a Linux EFI zboot image, do nothing and return success.
  */
-ssize_t unpack_efi_zboot_image(uint8_t **buffer, int *size)
+ssize_t unpack_efi_zboot_image(uint8_t **buffer, ssize_t *size)
 {
     const struct linux_efi_zboot_header *header;
     uint8_t *data = NULL;
-    int ploff, plsize;
+    ssize_t ploff, plsize;
     ssize_t bytes;
 
     /* ignore if this is too small to be a EFI zboot image */
diff --git a/include/hw/loader.h b/include/hw/loader.h
index 7f6d06b956fa9291e89a1d8b4e0ac44355dc12eb..8985046be40fc43741369a8431cd8e3590d1d72a 100644
--- a/include/hw/loader.h
+++ b/include/hw/loader.h
@@ -101,7 +101,7 @@  ssize_t load_image_gzipped_buffer(const char *filename, uint64_t max_sz,
  * Returns the size of the decompressed payload if decompression was performed
  * successfully.
  */
-ssize_t unpack_efi_zboot_image(uint8_t **buffer, int *size);
+ssize_t unpack_efi_zboot_image(uint8_t **buffer, ssize_t *size);
 
 #define ELF_LOAD_FAILED       -1
 #define ELF_LOAD_NOT_ELF      -2