24 #include <linux/slab.h>
25 #include <linux/stddef.h>
26 #include <linux/export.h>
39 static inline int elements_fit_in_base(
struct flex_array *
fa)
103 if (total > max_size)
105 ret = kzalloc(
sizeof(
struct flex_array), flags);
112 if (elements_fit_in_base(ret) && !(flags &
__GFP_ZERO))
120 unsigned int element_nr)
136 if (elements_fit_in_base(fa))
150 static unsigned int index_inside_part(
struct flex_array *
fa,
151 unsigned int element_nr,
152 unsigned int part_nr)
154 unsigned int part_offset;
204 if (elements_fit_in_base(fa))
207 part_nr = fa_element_to_part_nr(fa, element_nr);
208 part = __fa_get_part(fa, part_nr, flags);
212 dst = &part->
elements[index_inside_part(fa, element_nr, part_nr)];
235 if (elements_fit_in_base(fa))
238 part_nr = fa_element_to_part_nr(fa, element_nr);
239 part = fa->
parts[part_nr];
243 dst = &part->
elements[index_inside_part(fa, element_nr, part_nr)];
264 unsigned int nr_elements,
gfp_t flags)
272 if (!start && !nr_elements)
279 end = start + nr_elements - 1;
285 if (elements_fit_in_base(fa))
287 start_part = fa_element_to_part_nr(fa, start);
288 end_part = fa_element_to_part_nr(fa, end);
289 for (part_nr = start_part; part_nr <= end_part; part_nr++) {
290 part = __fa_get_part(fa, part_nr, flags);
319 if (elements_fit_in_base(fa))
322 part_nr = fa_element_to_part_nr(fa, element_nr);
323 part = fa->
parts[part_nr];
327 return &part->
elements[index_inside_part(fa, element_nr, part_nr)];
379 if (elements_fit_in_base(fa))
382 part = fa->
parts[part_nr];
385 if (part_is_free(part)) {