aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorEric Paris <eparis@redhat.com>2011-04-28 15:55:52 -0400
committerEric Paris <eparis@redhat.com>2011-04-28 16:12:47 -0400
commit5d30b10bd68df007e7ae21e77d1e0ce184b53040 (patch)
tree61d97a80d0fac7c6dfd97db7040fedd75771adda /lib
parentcb1e922fa104bb0bb3aa5fc6ca7f7e070f3b55e9 (diff)
flex_array: flex_array_prealloc takes a number of elements, not an end
Change flex_array_prealloc to take the number of elements for which space should be allocated instead of the last (inclusive) element. Users and documentation are updated accordingly. flex_arrays got introduced before they had users. When folks started using it, they ended up needing a different API than was coded up originally. This swaps over to the API that folks apparently need. Based-on-patch-by: Steffen Klassert <steffen.klassert@secunet.com> Signed-off-by: Eric Paris <eparis@redhat.com> Tested-by: Chris Richards <gizmo@giz-works.com> Acked-by: Dave Hansen <dave@linux.vnet.ibm.com> Cc: stable@kernel.org [2.6.38+]
Diffstat (limited to 'lib')
-rw-r--r--lib/flex_array.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/lib/flex_array.c b/lib/flex_array.c
index c0ea40ba2082..0c33b24498ba 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,13 +245,16 @@ 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
256 end = start + nr_elements - 1;
257
255 if (start >= fa->total_nr_elements || end >= fa->total_nr_elements) 258 if (start >= fa->total_nr_elements || end >= fa->total_nr_elements)
256 return -ENOSPC; 259 return -ENOSPC;
257 if (elements_fit_in_base(fa)) 260 if (elements_fit_in_base(fa))