[PATCH v4 0/4] alist: Implement a pointer list / array of structs
Simon Glass
sjg at chromium.org
Fri Jul 26 16:00:34 CEST 2024
This data structure provides a list of pointers / array of structures.
I was planning to use it for the lmb restructure, to allow it to
support any number of entries, but then I gave up on it.
There are quite a few places in U-Boot where such a list would be
useful, since it supports growing the array.
The series includes a patch to convert an existing function to use
this.
It adds a little under 300 bytes of code with Thumb2.
With this version, use of realloc() is option and off by default. This
reduces the size growth on xilinx_versal_mini_emmc0 (aarch64) from
1765 bytes to 636, for the str_to_list() patch.
The str_to_list() patch is marked as RFC since I beleive we have decided
not to apply it.
Example:
struct my_struct obj;
struct my_struct *ptr = alist_add(&lst, &obj, struct my_struct);
// now ptr is in the list
[1] https://patchwork.ozlabs.org/project/uboot/list/?series=371258&state=*
Changes in v4:
- Avoid using realloc() unless specifically enabled by Kconfig
Changes in v3:
- Add prototype for alist_expand_by()
- Update for alist_add() API change
Changes in v2:
- Fix 'typeee' typo
- Make alist_get_ptr() take a const alist *
- Make alist_add() take a struct rather than a pointer
- Declare alist_expand_by() as static
Simon Glass (4):
malloc: Support testing with realloc()
lib: Handle a special case with str_to_list()
alist: Add support for an allocated pointer list
RFC: lib: Convert str_to_list() to use alist
common/dlmalloc.c | 4 +
include/alist.h | 214 ++++++++++++++++++++++++++++++++++++++++++++++
lib/Kconfig | 10 +++
lib/Makefile | 1 +
lib/alist.c | 157 ++++++++++++++++++++++++++++++++++
lib/strto.c | 33 ++++---
test/lib/Makefile | 1 +
test/lib/alist.c | 197 ++++++++++++++++++++++++++++++++++++++++++
test/str_ut.c | 4 +-
9 files changed, 604 insertions(+), 17 deletions(-)
create mode 100644 include/alist.h
create mode 100644 lib/alist.c
create mode 100644 test/lib/alist.c
--
2.34.1
More information about the U-Boot
mailing list