From 89a8cabd09d5a58401863793d75e6e291e438c41 Mon Sep 17 00:00:00 2001 From: Eric Paris Date: Mon, 9 Aug 2010 17:20:56 -0700 Subject: [PATCH] --- yaml --- r: 207333 b: refs/heads/master c: ea98eed9bcb62d1319db8b1210712c6a110a886c h: refs/heads/master i: 207331: a2df85fb6d352d471bb9f4f58225165d742c1d43 v: v3 --- [refs] | 2 +- trunk/include/linux/flex_array.h | 5 +++++ trunk/lib/flex_array.c | 25 ++++++++++++++++++++++++- 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/[refs] b/[refs] index 81084be11389..ca574a1a1566 100644 --- a/[refs] +++ b/[refs] @@ -1,2 +1,2 @@ --- -refs/heads/master: 559b140a36613bb5b63f258b2ad833dad8cd11d9 +refs/heads/master: ea98eed9bcb62d1319db8b1210712c6a110a886c diff --git a/trunk/include/linux/flex_array.h b/trunk/include/linux/flex_array.h index 1d747f72298b..631b77f2ac70 100644 --- a/trunk/include/linux/flex_array.h +++ b/trunk/include/linux/flex_array.h @@ -70,4 +70,9 @@ int flex_array_clear(struct flex_array *fa, unsigned int element_nr); void *flex_array_get(struct flex_array *fa, unsigned int element_nr); int flex_array_shrink(struct flex_array *fa); +#define flex_array_put_ptr(fa, nr, src, gfp) \ + flex_array_put(fa, nr, &(void *)(src), gfp) + +void *flex_array_get_ptr(struct flex_array *fa, unsigned int element_nr); + #endif /* _FLEX_ARRAY_H */ diff --git a/trunk/lib/flex_array.c b/trunk/lib/flex_array.c index 41b1804fa728..77a6fea7481e 100644 --- a/trunk/lib/flex_array.c +++ b/trunk/lib/flex_array.c @@ -171,6 +171,8 @@ __fa_get_part(struct flex_array *fa, int part_nr, gfp_t flags) * Note that this *copies* the contents of @src into * the array. If you are trying to store an array of * pointers, make sure to pass in &ptr instead of ptr. + * You may instead wish to use the flex_array_put_ptr() + * helper function. * * Locking must be provided by the caller. */ @@ -265,7 +267,8 @@ int flex_array_prealloc(struct flex_array *fa, unsigned int start, * * Returns a pointer to the data at index @element_nr. Note * that this is a copy of the data that was passed in. If you - * are using this to store pointers, you'll get back &ptr. + * are using this to store pointers, you'll get back &ptr. You + * may instead wish to use the flex_array_get_ptr helper. * * Locking must be provided by the caller. */ @@ -286,6 +289,26 @@ void *flex_array_get(struct flex_array *fa, unsigned int element_nr) return &part->elements[index_inside_part(fa, element_nr)]; } +/** + * flex_array_get_ptr - pull a ptr back out of the array + * @fa: the flex array from which to extract data + * @element_nr: index of the element to fetch from the array + * + * Returns the pointer placed in the flex array at element_nr using + * flex_array_put_ptr(). This function should not be called if the + * element in question was not set using the _put_ptr() helper. + */ +void *flex_array_get_ptr(struct flex_array *fa, unsigned int element_nr) +{ + void **tmp; + + tmp = flex_array_get(fa, element_nr); + if (!tmp) + return NULL; + + return *tmp; +} + static int part_is_free(struct flex_array_part *part) { int i;