summaryrefslogtreecommitdiff
path: root/lib/alist.c
diff options
context:
space:
mode:
authorTom Rini <trini@konsulko.com>2024-11-03 17:23:29 -0600
committerTom Rini <trini@konsulko.com>2024-11-03 21:27:13 -0600
commitbf066dc3ebfe79ed24f889a41abe43d48d26c454 (patch)
tree7a967c47cb8d2bc242b241f35d3dcdaee257a883 /lib/alist.c
parent93cfcb026a124b133e85a025c51fcc6c85bc385e (diff)
parentdc24948a457e2f5cb7c518a9458be851b8b7e9ea (diff)
Merge tag 'dm-pull-2nov24' of https://source.denx.de/u-boot/custodians/u-boot-dm
CI: https://source.denx.de/u-boot/custodians/u-boot-dm/-/pipelines/23152 CI: https://dev.azure.com/simon0972/u-boot/_build/results?buildId=71&view=results - alist enhancements and fixes - minor test and sandbox fixes - some more x86/coreboot patches
Diffstat (limited to 'lib/alist.c')
-rw-r--r--lib/alist.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/lib/alist.c b/lib/alist.c
index b7928cad520..4ce651f5c45 100644
--- a/lib/alist.c
+++ b/lib/alist.c
@@ -41,6 +41,11 @@ void alist_uninit(struct alist *lst)
memset(lst, '\0', sizeof(struct alist));
}
+void alist_empty(struct alist *lst)
+{
+ lst->count = 0;
+}
+
/**
* alist_expand_to() - Expand a list to the given size
*
@@ -106,6 +111,42 @@ const void *alist_get_ptr(const struct alist *lst, uint index)
return lst->data + index * lst->obj_size;
}
+int alist_calc_index(const struct alist *lst, const void *ptr)
+{
+ uint index;
+
+ if (!lst->count || ptr < lst->data)
+ return -1;
+
+ index = (ptr - lst->data) / lst->obj_size;
+
+ return index;
+}
+
+void alist_update_end(struct alist *lst, const void *ptr)
+{
+ int index;
+
+ index = alist_calc_index(lst, ptr);
+ lst->count = index == -1 ? 0 : index;
+}
+
+bool alist_chk_ptr(const struct alist *lst, const void *ptr)
+{
+ int index = alist_calc_index(lst, ptr);
+
+ return index >= 0 && index < lst->count;
+}
+
+const void *alist_next_ptrd(const struct alist *lst, const void *ptr)
+{
+ int index = alist_calc_index(lst, ptr);
+
+ assert(index != -1);
+
+ return alist_get_ptr(lst, index + 1);
+}
+
void *alist_ensure_ptr(struct alist *lst, uint index)
{
uint minsize = index + 1;