1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <commonlib/helpers.h>
4 #include <commonlib/mem_pool.h>
6 void *mem_pool_alloc(struct mem_pool
*mp
, size_t sz
)
10 /* Make all allocations be at least 8 byte aligned. */
13 /* Determine if any space available. */
14 if ((mp
->size
- mp
->free_offset
) < sz
)
17 p
= &mp
->buf
[mp
->free_offset
];
19 mp
->free_offset
+= sz
;
25 void mem_pool_free(struct mem_pool
*mp
, void *p
)
27 /* Determine if p was the most recent allocation. */
28 if (p
== NULL
|| mp
->last_alloc
!= p
)
31 mp
->free_offset
= mp
->last_alloc
- mp
->buf
;
32 /* No way to track allocation before this one. */
33 mp
->last_alloc
= NULL
;