Lines Matching defs:element
25 static void poison_error(mempool_t *pool, void *element, size_t size,
33 pr_err("BUG: mempool element poison mismatch\n");
35 pr_err(" nr=%d @ %p: %s0x", nr, element, start > 0 ? "... " : "");
37 pr_cont("%x ", *(u8 *)(element + i));
42 static void __check_element(mempool_t *pool, void *element, size_t size)
44 u8 *obj = element;
51 poison_error(pool, element, size, i);
58 static void check_element(mempool_t *pool, void *element)
62 __check_element(pool, element, ksize(element));
66 void *addr = kmap_atomic((struct page *)element);
73 static void __poison_element(void *element, size_t size)
75 u8 *obj = element;
81 static void poison_element(mempool_t *pool, void *element)
85 __poison_element(element, ksize(element));
89 void *addr = kmap_atomic((struct page *)element);
96 static inline void check_element(mempool_t *pool, void *element)
99 static inline void poison_element(mempool_t *pool, void *element)
104 static __always_inline void kasan_poison_element(mempool_t *pool, void *element)
107 kasan_poison_kfree(element, _RET_IP_);
109 kasan_free_pages(element, (unsigned long)pool->pool_data);
112 static void kasan_unpoison_element(mempool_t *pool, void *element)
115 kasan_unpoison_slab(element);
117 kasan_alloc_pages(element, (unsigned long)pool->pool_data);
120 static __always_inline void add_element(mempool_t *pool, void *element)
123 poison_element(pool, element);
124 kasan_poison_element(pool, element);
125 pool->elements[pool->curr_nr++] = element;
130 void *element = pool->elements[--pool->curr_nr];
133 kasan_unpoison_element(pool, element);
134 check_element(pool, element);
135 return element;
152 void *element = remove_element(pool);
153 pool->free(element, pool->pool_data);
198 void *element;
200 element = pool->alloc(gfp_mask, pool->pool_data);
201 if (unlikely(!element)) {
205 add_element(pool, element);
217 * @alloc_fn: user-defined element-allocation function.
218 * @free_fn: user-defined element-freeing function.
239 * @alloc_fn: user-defined element-allocation function.
240 * @free_fn: user-defined element-freeing function.
299 void *element;
309 element = remove_element(pool);
311 pool->free(element, pool->pool_data);
340 element = pool->alloc(GFP_KERNEL, pool->pool_data);
341 if (!element)
345 add_element(pool, element);
348 pool->free(element, pool->pool_data); /* Raced */
360 * mempool_alloc - allocate an element from a specific memory pool
371 * Return: pointer to the allocated element or %NULL on error.
375 void *element;
391 element = pool->alloc(gfp_temp, pool->pool_data);
392 if (likely(element != NULL))
393 return element;
397 element = remove_element(pool);
405 kmemleak_update_trace(element);
406 return element;
425 /* Let's wait for someone else to return an element to @pool */
443 * mempool_free - return an element to the pool.
444 * @element: pool element pointer.
450 void mempool_free(void *element, mempool_t *pool)
454 if (unlikely(element == NULL))
459 * for @element and the following @pool->curr_nr. This ensures
461 * allocation of @element. This is necessary for fringe cases
462 * where @element was passed to this task without going through
480 * allocation of @element, any task which decremented curr_nr below
483 * to min_nr after the allocation of @element, the elements
493 add_element(pool, element);
500 pool->free(element, pool->pool_data);
515 void mempool_free_slab(void *element, void *pool_data)
518 kmem_cache_free(mem, element);
533 void mempool_kfree(void *element, void *pool_data)
535 kfree(element);
550 void mempool_free_pages(void *element, void *pool_data)
553 __free_pages(element, order);