diff options
Diffstat (limited to 'include/linux/flex_array.h')
| -rw-r--r-- | include/linux/flex_array.h | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/include/linux/flex_array.h b/include/linux/flex_array.h index b6efb0c64408..11366b3ff0b4 100644 --- a/include/linux/flex_array.h +++ b/include/linux/flex_array.h | |||
| @@ -61,16 +61,83 @@ struct flex_array { | |||
| 61 | FLEX_ARRAY_ELEMENTS_PER_PART(__element_size)); \ | 61 | FLEX_ARRAY_ELEMENTS_PER_PART(__element_size)); \ |
| 62 | } | 62 | } |
| 63 | 63 | ||
| 64 | /** | ||
| 65 | * flex_array_alloc() - Creates a flexible array. | ||
| 66 | * @element_size: individual object size. | ||
| 67 | * @total: maximum number of objects which can be stored. | ||
| 68 | * @flags: GFP flags | ||
| 69 | * | ||
| 70 | * Return: Returns an object of structure flex_array. | ||
| 71 | */ | ||
| 64 | struct flex_array *flex_array_alloc(int element_size, unsigned int total, | 72 | struct flex_array *flex_array_alloc(int element_size, unsigned int total, |
| 65 | gfp_t flags); | 73 | gfp_t flags); |
| 74 | |||
| 75 | /** | ||
| 76 | * flex_array_prealloc() - Ensures that memory for the elements indexed in the | ||
| 77 | * range defined by start and nr_elements has been allocated. | ||
| 78 | * @fa: array to allocate memory to. | ||
| 79 | * @start: start address | ||
| 80 | * @nr_elements: number of elements to be allocated. | ||
| 81 | * @flags: GFP flags | ||
| 82 | * | ||
| 83 | */ | ||
| 66 | int flex_array_prealloc(struct flex_array *fa, unsigned int start, | 84 | int flex_array_prealloc(struct flex_array *fa, unsigned int start, |
| 67 | unsigned int nr_elements, gfp_t flags); | 85 | unsigned int nr_elements, gfp_t flags); |
| 86 | |||
| 87 | /** | ||
| 88 | * flex_array_free() - Removes all elements of a flexible array. | ||
| 89 | * @fa: array to be freed. | ||
| 90 | */ | ||
| 68 | void flex_array_free(struct flex_array *fa); | 91 | void flex_array_free(struct flex_array *fa); |
| 92 | |||
| 93 | /** | ||
| 94 | * flex_array_free_parts() - Removes all elements of a flexible array, but | ||
| 95 | * leaves the array itself in place. | ||
| 96 | * @fa: array to be emptied. | ||
| 97 | */ | ||
| 69 | void flex_array_free_parts(struct flex_array *fa); | 98 | void flex_array_free_parts(struct flex_array *fa); |
| 99 | |||
| 100 | /** | ||
| 101 | * flex_array_put() - Stores data into a flexible array. | ||
| 102 | * @fa: array where element is to be stored. | ||
| 103 | * @element_nr: position to copy, must be less than the maximum specified when | ||
| 104 | * the array was created. | ||
| 105 | * @src: data source to be copied into the array. | ||
| 106 | * @flags: GFP flags | ||
| 107 | * | ||
| 108 | * Return: Returns zero on success, a negative error code otherwise. | ||
| 109 | */ | ||
| 70 | int flex_array_put(struct flex_array *fa, unsigned int element_nr, void *src, | 110 | int flex_array_put(struct flex_array *fa, unsigned int element_nr, void *src, |
| 71 | gfp_t flags); | 111 | gfp_t flags); |
| 112 | |||
| 113 | /** | ||
| 114 | * flex_array_clear() - Clears an individual element in the array, sets the | ||
| 115 | * given element to FLEX_ARRAY_FREE. | ||
| 116 | * @element_nr: element position to clear. | ||
| 117 | * @fa: array to which element to be cleared belongs. | ||
| 118 | * | ||
| 119 | * Return: Returns zero on success, -EINVAL otherwise. | ||
| 120 | */ | ||
| 72 | int flex_array_clear(struct flex_array *fa, unsigned int element_nr); | 121 | int flex_array_clear(struct flex_array *fa, unsigned int element_nr); |
| 122 | |||
| 123 | /** | ||
| 124 | * flex_array_get() - Retrieves data into a flexible array. | ||
| 125 | * | ||
| 126 | * @element_nr: Element position to retrieve data from. | ||
| 127 | * @fa: array from which data is to be retrieved. | ||
| 128 | * | ||
| 129 | * Return: Returns a pointer to the data element, or NULL if that | ||
| 130 | * particular element has never been allocated. | ||
| 131 | */ | ||
| 73 | void *flex_array_get(struct flex_array *fa, unsigned int element_nr); | 132 | void *flex_array_get(struct flex_array *fa, unsigned int element_nr); |
| 133 | |||
| 134 | /** | ||
| 135 | * flex_array_shrink() - Reduces the allocated size of an array. | ||
| 136 | * @fa: array to shrink. | ||
| 137 | * | ||
| 138 | * Return: Returns number of pages of memory actually freed. | ||
| 139 | * | ||
| 140 | */ | ||
| 74 | int flex_array_shrink(struct flex_array *fa); | 141 | int flex_array_shrink(struct flex_array *fa); |
| 75 | 142 | ||
| 76 | #define flex_array_put_ptr(fa, nr, src, gfp) \ | 143 | #define flex_array_put_ptr(fa, nr, src, gfp) \ |
