static struct flex_array *fa_alloc(size_t elem_size, size_t elem_count, gfp_t gfp) { struct flex_array *result; int err; result = flex_array_alloc(elem_size, elem_count, gfp); if (result) { err = flex_array_prealloc(result, 0, elem_count, gfp); if (err) { flex_array_free(result); result = NULL; } } return result; }
void avtab_destroy(struct avtab *h) { int i; struct avtab_node *cur, *temp; if (!h || !h->htable) return; for (i = 0; i < h->nslot; i++) { cur = flex_array_get_ptr(h->htable, i); while (cur) { temp = cur; cur = cur->next; kmem_cache_free(avtab_node_cachep, temp); } } flex_array_free(h->htable); h->htable = NULL; h->nslot = 0; h->mask = 0; }
static struct flex_array *alloc_buckets(unsigned int n_buckets) { struct flex_array *buckets; int i, err; buckets = flex_array_alloc(sizeof(struct hlist_head *), n_buckets, GFP_KERNEL); if (!buckets) return NULL; err = flex_array_prealloc(buckets, 0, n_buckets, GFP_KERNEL); if (err) { flex_array_free(buckets); return NULL; } for (i = 0; i < n_buckets; i++) INIT_HLIST_HEAD((struct hlist_head *) flex_array_get(buckets, i)); return buckets; }
static void free_buckets(struct flex_array *buckets) { flex_array_free(buckets); }
static void fa_free(struct flex_array *fa) { if (fa) flex_array_free(fa); }