diff options
-rw-r--r-- | include/linux/flex_array.h | 5 | ||||
-rw-r--r-- | lib/flex_array.c | 25 |
2 files changed, 29 insertions, 1 deletions
diff --git a/include/linux/flex_array.h b/include/linux/flex_array.h index 1d747f72298b..631b77f2ac70 100644 --- a/include/linux/flex_array.h +++ b/include/linux/flex_array.h | |||
@@ -70,4 +70,9 @@ int flex_array_clear(struct flex_array *fa, unsigned int element_nr); | |||
70 | void *flex_array_get(struct flex_array *fa, unsigned int element_nr); | 70 | void *flex_array_get(struct flex_array *fa, unsigned int element_nr); |
71 | int flex_array_shrink(struct flex_array *fa); | 71 | int flex_array_shrink(struct flex_array *fa); |
72 | 72 | ||
73 | #define flex_array_put_ptr(fa, nr, src, gfp) \ | ||
74 | flex_array_put(fa, nr, &(void *)(src), gfp) | ||
75 | |||
76 | void *flex_array_get_ptr(struct flex_array *fa, unsigned int element_nr); | ||
77 | |||
73 | #endif /* _FLEX_ARRAY_H */ | 78 | #endif /* _FLEX_ARRAY_H */ |
diff --git a/lib/flex_array.c b/lib/flex_array.c index 41b1804fa728..77a6fea7481e 100644 --- a/lib/flex_array.c +++ b/lib/flex_array.c | |||
@@ -171,6 +171,8 @@ __fa_get_part(struct flex_array *fa, int part_nr, gfp_t flags) | |||
171 | * Note that this *copies* the contents of @src into | 171 | * Note that this *copies* the contents of @src into |
172 | * the array. If you are trying to store an array of | 172 | * the array. If you are trying to store an array of |
173 | * pointers, make sure to pass in &ptr instead of ptr. | 173 | * pointers, make sure to pass in &ptr instead of ptr. |
174 | * You may instead wish to use the flex_array_put_ptr() | ||
175 | * helper function. | ||
174 | * | 176 | * |
175 | * Locking must be provided by the caller. | 177 | * Locking must be provided by the caller. |
176 | */ | 178 | */ |
@@ -265,7 +267,8 @@ int flex_array_prealloc(struct flex_array *fa, unsigned int start, | |||
265 | * | 267 | * |
266 | * Returns a pointer to the data at index @element_nr. Note | 268 | * Returns a pointer to the data at index @element_nr. Note |
267 | * that this is a copy of the data that was passed in. If you | 269 | * that this is a copy of the data that was passed in. If you |
268 | * are using this to store pointers, you'll get back &ptr. | 270 | * are using this to store pointers, you'll get back &ptr. You |
271 | * may instead wish to use the flex_array_get_ptr helper. | ||
269 | * | 272 | * |
270 | * Locking must be provided by the caller. | 273 | * Locking must be provided by the caller. |
271 | */ | 274 | */ |
@@ -286,6 +289,26 @@ void *flex_array_get(struct flex_array *fa, unsigned int element_nr) | |||
286 | return &part->elements[index_inside_part(fa, element_nr)]; | 289 | return &part->elements[index_inside_part(fa, element_nr)]; |
287 | } | 290 | } |
288 | 291 | ||
292 | /** | ||
293 | * flex_array_get_ptr - pull a ptr back out of the array | ||
294 | * @fa: the flex array from which to extract data | ||
295 | * @element_nr: index of the element to fetch from the array | ||
296 | * | ||
297 | * Returns the pointer placed in the flex array at element_nr using | ||
298 | * flex_array_put_ptr(). This function should not be called if the | ||
299 | * element in question was not set using the _put_ptr() helper. | ||
300 | */ | ||
301 | void *flex_array_get_ptr(struct flex_array *fa, unsigned int element_nr) | ||
302 | { | ||
303 | void **tmp; | ||
304 | |||
305 | tmp = flex_array_get(fa, element_nr); | ||
306 | if (!tmp) | ||
307 | return NULL; | ||
308 | |||
309 | return *tmp; | ||
310 | } | ||
311 | |||
289 | static int part_is_free(struct flex_array_part *part) | 312 | static int part_is_free(struct flex_array_part *part) |
290 | { | 313 | { |
291 | int i; | 314 | int i; |