aboutsummaryrefslogtreecommitdiffstats
path: root/lib/flex_array.c
diff options
context:
space:
mode:
authorStefan Richter <stefanr@s5r6.in-berlin.de>2011-05-10 14:52:07 -0400
committerStefan Richter <stefanr@s5r6.in-berlin.de>2011-05-10 16:50:41 -0400
commit020abf03cd659388f94cb328e1e1df0656e0d7ff (patch)
tree40d05011708ad1b4a05928d167eb120420581aa6 /lib/flex_array.c
parent0ff8fbc61727c926883eec381fbd3d32d1fab504 (diff)
parent693d92a1bbc9e42681c42ed190bd42b636ca876f (diff)
Merge tag 'v2.6.39-rc7'
in order to pull in changes in drivers/media/dvb/firewire/ and sound/firewire/.
Diffstat (limited to 'lib/flex_array.c')
-rw-r--r--lib/flex_array.c34
1 files changed, 28 insertions, 6 deletions
diff --git a/lib/flex_array.c b/lib/flex_array.c
index 77a6fea7481e..854b57bd7d9d 100644
--- a/lib/flex_array.c
+++ b/lib/flex_array.c
@@ -23,6 +23,7 @@
23#include <linux/flex_array.h> 23#include <linux/flex_array.h>
24#include <linux/slab.h> 24#include <linux/slab.h>
25#include <linux/stddef.h> 25#include <linux/stddef.h>
26#include <linux/module.h>
26 27
27struct flex_array_part { 28struct flex_array_part {
28 char elements[FLEX_ARRAY_PART_SIZE]; 29 char elements[FLEX_ARRAY_PART_SIZE];
@@ -103,6 +104,7 @@ struct flex_array *flex_array_alloc(int element_size, unsigned int total,
103 FLEX_ARRAY_BASE_BYTES_LEFT); 104 FLEX_ARRAY_BASE_BYTES_LEFT);
104 return ret; 105 return ret;
105} 106}
107EXPORT_SYMBOL(flex_array_alloc);
106 108
107static int fa_element_to_part_nr(struct flex_array *fa, 109static int fa_element_to_part_nr(struct flex_array *fa,
108 unsigned int element_nr) 110 unsigned int element_nr)
@@ -126,12 +128,14 @@ void flex_array_free_parts(struct flex_array *fa)
126 for (part_nr = 0; part_nr < FLEX_ARRAY_NR_BASE_PTRS; part_nr++) 128 for (part_nr = 0; part_nr < FLEX_ARRAY_NR_BASE_PTRS; part_nr++)
127 kfree(fa->parts[part_nr]); 129 kfree(fa->parts[part_nr]);
128} 130}
131EXPORT_SYMBOL(flex_array_free_parts);
129 132
130void flex_array_free(struct flex_array *fa) 133void flex_array_free(struct flex_array *fa)
131{ 134{
132 flex_array_free_parts(fa); 135 flex_array_free_parts(fa);
133 kfree(fa); 136 kfree(fa);
134} 137}
138EXPORT_SYMBOL(flex_array_free);
135 139
136static unsigned int index_inside_part(struct flex_array *fa, 140static unsigned int index_inside_part(struct flex_array *fa,
137 unsigned int element_nr) 141 unsigned int element_nr)
@@ -196,6 +200,7 @@ int flex_array_put(struct flex_array *fa, unsigned int element_nr, void *src,
196 memcpy(dst, src, fa->element_size); 200 memcpy(dst, src, fa->element_size);
197 return 0; 201 return 0;
198} 202}
203EXPORT_SYMBOL(flex_array_put);
199 204
200/** 205/**
201 * flex_array_clear - clear element in array at @element_nr 206 * flex_array_clear - clear element in array at @element_nr
@@ -223,13 +228,14 @@ int flex_array_clear(struct flex_array *fa, unsigned int element_nr)
223 memset(dst, FLEX_ARRAY_FREE, fa->element_size); 228 memset(dst, FLEX_ARRAY_FREE, fa->element_size);
224 return 0; 229 return 0;
225} 230}
231EXPORT_SYMBOL(flex_array_clear);
226 232
227/** 233/**
228 * flex_array_prealloc - guarantee that array space exists 234 * flex_array_prealloc - guarantee that array space exists
229 * @fa: the flex array for which to preallocate parts 235 * @fa: the flex array for which to preallocate parts
230 * @start: index of first array element for which space is allocated 236 * @start: index of first array element for which space is allocated
231 * @end: index of last (inclusive) element for which space is allocated 237 * @nr_elements: number of elements for which space is allocated
232 * @flags: page allocation flags 238 * @flags: page allocation flags
233 * 239 *
234 * This will guarantee that no future calls to flex_array_put() 240 * This will guarantee that no future calls to flex_array_put()
235 * 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
@@ -239,14 +245,24 @@ int flex_array_clear(struct flex_array *fa, unsigned int element_nr)
239 * Locking must be provided by the caller. 245 * Locking must be provided by the caller.
240 */ 246 */
241int flex_array_prealloc(struct flex_array *fa, unsigned int start, 247int flex_array_prealloc(struct flex_array *fa, unsigned int start,
242 unsigned int end, gfp_t flags) 248 unsigned int nr_elements, gfp_t flags)
243{ 249{
244 int start_part; 250 int start_part;
245 int end_part; 251 int end_part;
246 int part_nr; 252 int part_nr;
253 unsigned int end;
247 struct flex_array_part *part; 254 struct flex_array_part *part;
248 255
249 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)
250 return -ENOSPC; 266 return -ENOSPC;
251 if (elements_fit_in_base(fa)) 267 if (elements_fit_in_base(fa))
252 return 0; 268 return 0;
@@ -259,6 +275,7 @@ int flex_array_prealloc(struct flex_array *fa, unsigned int start,
259 } 275 }
260 return 0; 276 return 0;
261} 277}
278EXPORT_SYMBOL(flex_array_prealloc);
262 279
263/** 280/**
264 * flex_array_get - pull data back out of the array 281 * flex_array_get - pull data back out of the array
@@ -288,6 +305,7 @@ void *flex_array_get(struct flex_array *fa, unsigned int element_nr)
288 } 305 }
289 return &part->elements[index_inside_part(fa, element_nr)]; 306 return &part->elements[index_inside_part(fa, element_nr)];
290} 307}
308EXPORT_SYMBOL(flex_array_get);
291 309
292/** 310/**
293 * flex_array_get_ptr - pull a ptr back out of the array 311 * flex_array_get_ptr - pull a ptr back out of the array
@@ -308,6 +326,7 @@ void *flex_array_get_ptr(struct flex_array *fa, unsigned int element_nr)
308 326
309 return *tmp; 327 return *tmp;
310} 328}
329EXPORT_SYMBOL(flex_array_get_ptr);
311 330
312static int part_is_free(struct flex_array_part *part) 331static int part_is_free(struct flex_array_part *part)
313{ 332{
@@ -334,6 +353,8 @@ int flex_array_shrink(struct flex_array *fa)
334 int part_nr; 353 int part_nr;
335 int ret = 0; 354 int ret = 0;
336 355
356 if (!fa->total_nr_elements)
357 return 0;
337 if (elements_fit_in_base(fa)) 358 if (elements_fit_in_base(fa))
338 return ret; 359 return ret;
339 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++) {
@@ -348,3 +369,4 @@ int flex_array_shrink(struct flex_array *fa)
348 } 369 }
349 return ret; 370 return ret;
350} 371}
372EXPORT_SYMBOL(flex_array_shrink);