1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /* This file is part of the coreboot project. */
4 #include <commonlib/helpers.h>
5 #include <commonlib/mem_pool.h>
7 void *mem_pool_alloc(struct mem_pool
*mp
, size_t sz
)
11 /* Make all allocations be at least 8 byte aligned. */
14 /* Determine if any space available. */
15 if ((mp
->size
- mp
->free_offset
) < sz
)
18 p
= &mp
->buf
[mp
->free_offset
];
20 mp
->free_offset
+= sz
;
26 void mem_pool_free(struct mem_pool
*mp
, void *p
)
28 /* Determine if p was the most recent allocation. */
29 if (p
== NULL
|| mp
->last_alloc
!= p
)
32 mp
->free_offset
= mp
->last_alloc
- mp
->buf
;
33 /* No way to track allocation before this one. */
34 mp
->last_alloc
= NULL
;