static inline int ptr_valid(struct pool *pool, void *ptr)
{
- unsigned int pool_size = pool->nr_blocks * SMALLOC_BPL;
+ unsigned int pool_size = (pool->nr_blocks + 1) * SMALLOC_BPL;
return (ptr >= pool->map) && (ptr < pool->map + pool_size);
}
+static inline unsigned int size_to_blocks(unsigned int size)
+{
+ return (size + SMALLOC_BPB - 1) / SMALLOC_BPB;
+}
+
static int blocks_iter(unsigned int *map, unsigned int idx,
unsigned int nr_blocks,
int (*func)(unsigned int *map, unsigned int mask))
sfree_pool(pool, ptr);
}
-static inline unsigned int size_to_blocks(unsigned int size)
-{
- return (size + SMALLOC_BPB - 1) / SMALLOC_BPB;
-}
-
static void *__smalloc_pool(struct pool *pool, unsigned int size)
{
unsigned int nr_blocks;
#endif
ptr = __smalloc_pool(pool, alloc_size);
- if (!ptr) {
- printf("failed allocating %u\n", alloc_size);
+ if (!ptr)
return NULL;
- }
hdr = ptr;
hdr->size = alloc_size;