/* Since 64-bit pointers are twice the size, we lose half the capacity in the base structure. Also note that no effort is made to efficiently pack objects across page boundaries.  */
struct flex_array* flex_array_alloc(int element_size, unsigned int total, gfp_t flags)
/* Since 64-bit pointers are twice the size, we lose half the capacity in the base structure. Also note that no effort is made to efficiently pack objects across page boundaries.  */
struct flex_array* flex_array_alloc(int element_size, unsigned int total, gfp_t flags)
{
	struct flex_array *ret;
	int max_size = FLEX_ARRAY_NR_BASE_PTRS *
				FLEX_ARRAY_ELEMENTS_PER_PART(element_size);
	if (total > max_size)
		return NULL;
	ret = kzalloc(sizeof(struct flex_array), flags);
	if (!ret)
		return NULL;
	ret->element_size = element_size;
	ret->total_nr_elements = total;
	if (elements_fit_in_base(ret) && !(flags & __GFP_ZERO))
		memset(ret->parts[0], FLEX_ARRAY_FREE,
						FLEX_ARRAY_BASE_BYTES_LEFT);
	return ret;
}