Lines Matching refs:element

24 static void poison_error(mempool_t *pool, void *element, size_t size,
32 pr_err("BUG: mempool element poison mismatch\n");
34 pr_err(" nr=%d @ %p: %s0x", nr, element, start > 0 ? "... " : "");
36 pr_cont("%x ", *(u8 *)(element + i));
41 static void __check_element(mempool_t *pool, void *element, size_t size)
43 u8 *obj = element;
50 poison_error(pool, element, size, i);
57 static void check_element(mempool_t *pool, void *element)
59 /* Skip checking: KASAN might save its metadata in the element. */
65 __check_element(pool, element, (size_t)pool->pool_data);
67 __check_element(pool, element, kmem_cache_size(pool->pool_data));
71 void *addr = kmap_local_page((struct page *)element);
78 static void __poison_element(void *element, size_t size)
80 u8 *obj = element;
86 static void poison_element(mempool_t *pool, void *element)
88 /* Skip poisoning: KASAN might save its metadata in the element. */
94 __poison_element(element, (size_t)pool->pool_data);
96 __poison_element(element, kmem_cache_size(pool->pool_data));
100 void *addr = kmap_local_page((struct page *)element);
107 static inline void check_element(mempool_t *pool, void *element)
110 static inline void poison_element(mempool_t *pool, void *element)
115 static __always_inline bool kasan_poison_element(mempool_t *pool, void *element)
118 return kasan_mempool_poison_object(element);
120 return kasan_mempool_poison_pages(element,
125 static void kasan_unpoison_element(mempool_t *pool, void *element)
128 kasan_mempool_unpoison_object(element, (size_t)pool->pool_data);
130 kasan_mempool_unpoison_object(element,
133 kasan_mempool_unpoison_pages(element,
137 static __always_inline void add_element(mempool_t *pool, void *element)
140 poison_element(pool, element);
141 if (kasan_poison_element(pool, element))
142 pool->elements[pool->curr_nr++] = element;
147 void *element = pool->elements[--pool->curr_nr];
150 kasan_unpoison_element(pool, element);
151 check_element(pool, element);
152 return element;
169 void *element = remove_element(pool);
170 pool->free(element, pool->pool_data);
215 void *element;
217 element = pool->alloc(gfp_mask, pool->pool_data);
218 if (unlikely(!element)) {
222 add_element(pool, element);
234 * @alloc_fn: user-defined element-allocation function.
235 * @free_fn: user-defined element-freeing function.
256 * @alloc_fn: user-defined element-allocation function.
257 * @free_fn: user-defined element-freeing function.
310 void *element;
320 element = remove_element(pool);
322 pool->free(element, pool->pool_data);
351 element = pool->alloc(GFP_KERNEL, pool->pool_data);
352 if (!element)
356 add_element(pool, element);
359 pool->free(element, pool->pool_data); /* Raced */
371 * mempool_alloc - allocate an element from a specific memory pool
382 * Return: pointer to the allocated element or %NULL on error.
386 void *element;
402 element = pool->alloc(gfp_temp, pool->pool_data);
403 if (likely(element != NULL))
404 return element;
408 element = remove_element(pool);
416 kmemleak_update_trace(element);
417 return element;
436 /* Let's wait for someone else to return an element to @pool */
454 * mempool_alloc_preallocated - allocate an element from preallocated elements
460 * an element from the preallocated elements. It does not sleep and immediately
463 * Return: pointer to the allocated element or %NULL if no elements are
468 void *element;
473 element = remove_element(pool);
481 kmemleak_update_trace(element);
482 return element;
491 * mempool_free - return an element to the pool.
492 * @element: pool element pointer.
498 void mempool_free(void *element, mempool_t *pool)
502 if (unlikely(element == NULL))
507 * for @element and the following @pool->curr_nr. This ensures
509 * allocation of @element. This is necessary for fringe cases
510 * where @element was passed to this task without going through
528 * allocation of @element, any task which decremented curr_nr below
531 * to min_nr after the allocation of @element, the elements
541 add_element(pool, element);
548 pool->free(element, pool->pool_data);
563 void mempool_free_slab(void *element, void *pool_data)
566 kmem_cache_free(mem, element);
581 void mempool_kfree(void *element, void *pool_data)
583 kfree(element);
594 void mempool_kvfree(void *element, void *pool_data)
596 kvfree(element);
611 void mempool_free_pages(void *element, void *pool_data)
614 __free_pages(element, order);