diff options
| author | James Morris <jmorris@namei.org> | 2009-09-30 07:47:33 +1000 |
|---|---|---|
| committer | James Morris <jmorris@namei.org> | 2009-09-30 07:47:33 +1000 |
| commit | 1669b049db50fc7f1d4e694fb115a0f408c63fce (patch) | |
| tree | 9b3b90b5cbff9b8f30ecf0b2a44896ce8bef0c20 /include/linux/flex_array.h | |
| parent | 7f366784f5c2b8fc0658b5b374f4c63ee42c789f (diff) | |
| parent | 17d857be649a21ca90008c6dc425d849fa83db5c (diff) | |
Merge branch 'master' into next
Diffstat (limited to 'include/linux/flex_array.h')
| -rw-r--r-- | include/linux/flex_array.h | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/include/linux/flex_array.h b/include/linux/flex_array.h index 45ff18491514..1d747f72298b 100644 --- a/include/linux/flex_array.h +++ b/include/linux/flex_array.h @@ -31,10 +31,32 @@ struct flex_array { }; }; -#define FLEX_ARRAY_INIT(size, total) { { {\ - .element_size = (size), \ - .total_nr_elements = (total), \ -} } } +/* Number of bytes left in base struct flex_array, excluding metadata */ +#define FLEX_ARRAY_BASE_BYTES_LEFT \ + (FLEX_ARRAY_BASE_SIZE - offsetof(struct flex_array, parts)) + +/* Number of pointers in base to struct flex_array_part pages */ +#define FLEX_ARRAY_NR_BASE_PTRS \ + (FLEX_ARRAY_BASE_BYTES_LEFT / sizeof(struct flex_array_part *)) + +/* Number of elements of size that fit in struct flex_array_part */ +#define FLEX_ARRAY_ELEMENTS_PER_PART(size) \ + (FLEX_ARRAY_PART_SIZE / size) + +/* + * Defines a statically allocated flex array and ensures its parameters are + * valid. + */ +#define DEFINE_FLEX_ARRAY(__arrayname, __element_size, __total) \ + struct flex_array __arrayname = { { { \ + .element_size = (__element_size), \ + .total_nr_elements = (__total), \ + } } }; \ + static inline void __arrayname##_invalid_parameter(void) \ + { \ + BUILD_BUG_ON((__total) > FLEX_ARRAY_NR_BASE_PTRS * \ + FLEX_ARRAY_ELEMENTS_PER_PART(__element_size)); \ + } struct flex_array *flex_array_alloc(int element_size, unsigned int total, gfp_t flags); @@ -44,6 +66,8 @@ void flex_array_free(struct flex_array *fa); void flex_array_free_parts(struct flex_array *fa); int flex_array_put(struct flex_array *fa, unsigned int element_nr, void *src, gfp_t flags); +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); #endif /* _FLEX_ARRAY_H */ |
