aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/flex_array.c24
1 files changed, 18 insertions, 6 deletions
diff --git a/lib/flex_array.c b/lib/flex_array.c
index c0ea40ba2082..854b57bd7d9d 100644
--- a/lib/flex_array.c
+++ b/lib/flex_array.c
@@ -232,10 +232,10 @@ EXPORT_SYMBOL(flex_array_clear);
232 232
233/** 233/**
234 * flex_array_prealloc - guarantee that array space exists 234 * flex_array_prealloc - guarantee that array space exists
235 * @fa: the flex array for which to preallocate parts 235 * @fa: the flex array for which to preallocate parts
236 * @start: index of first array element for which space is allocated 236 * @start: index of first array element for which space is allocated
237 * @end: index of last (inclusive) element for which space is allocated 237 * @nr_elements: number of elements for which space is allocated
238 * @flags: page allocation flags 238 * @flags: page allocation flags
239 * 239 *
240 * This will guarantee that no future calls to flex_array_put() 240 * This will guarantee that no future calls to flex_array_put()
241 * will allocate memory. It can be used if you are expecting to 241 * will allocate memory. It can be used if you are expecting to
@@ -245,14 +245,24 @@ EXPORT_SYMBOL(flex_array_clear);
245 * Locking must be provided by the caller. 245 * Locking must be provided by the caller.
246 */ 246 */
247int flex_array_prealloc(struct flex_array *fa, unsigned int start, 247int flex_array_prealloc(struct flex_array *fa, unsigned int start,
248 unsigned int end, gfp_t flags) 248 unsigned int nr_elements, gfp_t flags)
249{ 249{
250 int start_part; 250 int start_part;
251 int end_part; 251 int end_part;
252 int part_nr; 252 int part_nr;
253 unsigned int end;
253 struct flex_array_part *part; 254 struct flex_array_part *part;
254 255
255 if (start >= fa->total_nr_elements || end >= fa->total_nr_elements) 256 if (!start && !nr_elements)
257 return 0;
258 if (start >= fa->total_nr_elements)
259 return -ENOSPC;
260 if (!nr_elements)
261 return 0;
262
263 end = start + nr_elements - 1;
264
265 if (end >= fa->total_nr_elements)
256 return -ENOSPC; 266 return -ENOSPC;
257 if (elements_fit_in_base(fa)) 267 if (elements_fit_in_base(fa))
258 return 0; 268 return 0;
@@ -343,6 +353,8 @@ int flex_array_shrink(struct flex_array *fa)
343 int part_nr; 353 int part_nr;
344 int ret = 0; 354 int ret = 0;
345 355
356 if (!fa->total_nr_elements)
357 return 0;
346 if (elements_fit_in_base(fa)) 358 if (elements_fit_in_base(fa))
347 return ret; 359 return ret;
348 for (part_nr = 0; part_nr < FLEX_ARRAY_NR_BASE_PTRS; part_nr++) { 360 for (part_nr = 0; part_nr < FLEX_ARRAY_NR_BASE_PTRS; part_nr++) {