[PATCH v3 3/4] lib: efi_loader: efi_memory.c: add efi_realloc() for realloc memory

Simon Glass sjg at chromium.org
Wed May 28 09:35:45 CEST 2025


Hi Paul,

On Wed, 28 May 2025 at 01:24, Paul Liu <paul.liu at linaro.org> wrote:
>
>
>
> On Fri, 23 May 2025 at 14:44, Simon Glass <sjg at chromium.org> wrote:
>>
>> Hi,
>>
>> On Thu, 22 May 2025 at 03:18, Ying-Chun Liu (PaulLiu)
>> <paulliu at debian.org> wrote:
>> >
>> > From: "Ying-Chun Liu (PaulLiu)" <paul.liu at linaro.org>
>> >
>> > Add efi_realloc() for realloc memory that previously alloc by efi_alloc().
>> >
>> > Signed-off-by: Ying-Chun Liu (PaulLiu) <paul.liu at linaro.org>
>> > Cc: Heinrich Schuchardt <xypron.glpk at gmx.de>
>> > Cc: Ilias Apalodimas <ilias.apalodimas at linaro.org>
>> > Cc: Peter Robinson <pbrobinson at gmail.com>
>> > ---
>> >  include/efi_loader.h        |  2 ++
>> >  lib/efi_loader/efi_memory.c | 52 +++++++++++++++++++++++++++++++++++++
>> >  2 files changed, 54 insertions(+)
>> >
>> > diff --git a/include/efi_loader.h b/include/efi_loader.h
>> > index d0c72d0bc58..ff7ca5a0480 100644
>> > --- a/include/efi_loader.h
>> > +++ b/include/efi_loader.h
>> > @@ -878,6 +878,8 @@ efi_status_t efi_next_variable_name(efi_uintn_t *size, u16 **buf,
>> >  #define efi_size_in_pages(size) (((size) + EFI_PAGE_MASK) >> EFI_PAGE_SHIFT)
>> >  /* Allocate boot service data pool memory */
>> >  void *efi_alloc(size_t len);
>> > +/* Reallocate boot service data pool memory */
>> > +void *efi_realloc(void *ptr, size_t len);
>> >  /* Allocate pages on the specified alignment */
>> >  void *efi_alloc_aligned_pages(u64 len, int memory_type, size_t align);
>> >  /* More specific EFI memory allocator, called by EFI payloads */
>> > diff --git a/lib/efi_loader/efi_memory.c b/lib/efi_loader/efi_memory.c
>> > index 0abb1f6159a..4c76df642dc 100644
>> > --- a/lib/efi_loader/efi_memory.c
>> > +++ b/lib/efi_loader/efi_memory.c
>> > @@ -666,6 +666,58 @@ void *efi_alloc(size_t size)
>> >         return buf;
>> >  }
>> >
>> > +/**
>> > + * efi_realloc() - reallocate boot services data pool memory
>> > + *
>> > + * Reallocate memory from pool for a new size and copy the data from old one.
>> > + *
>> > + * @ptr:       pointer to old buffer
>> > + * @size:      number of bytes to allocate
>> > + * Return:     pointer to allocated memory or NULL
>> > + */
>>
>> Should go in header file
>
>
> Hi Simon,
>
> I look into the code. It seems other functions in the same .c file put the comments in the .c file instead of the header file.
> Should I move the comments to the header file? I'm a bit confused.

Normally we use the header file for exported functions and comments.
Sometimes people don't like to convert everything, as I did with [1],
for example. So a middle path is to just make sure you add new
exported functions in the header file.

Regards,
SImon

[1] https://patchwork.ozlabs.org/project/uboot/patch/20250524172827.1243975-2-sjg@chromium.org/


More information about the U-Boot mailing list