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; }
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; }