aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/linux/flex_array.h1
-rw-r--r--lib/flex_array.c26
2 files changed, 27 insertions, 0 deletions
diff --git a/include/linux/flex_array.h b/include/linux/flex_array.h
index 45ff18491514..3887b21f883f 100644
--- a/include/linux/flex_array.h
+++ b/include/linux/flex_array.h
@@ -44,6 +44,7 @@ void flex_array_free(struct flex_array *fa);
44void flex_array_free_parts(struct flex_array *fa); 44void flex_array_free_parts(struct flex_array *fa);
45int flex_array_put(struct flex_array *fa, unsigned int element_nr, void *src, 45int flex_array_put(struct flex_array *fa, unsigned int element_nr, void *src,
46 gfp_t flags); 46 gfp_t flags);
47int flex_array_clear(struct flex_array *fa, unsigned int element_nr);
47void *flex_array_get(struct flex_array *fa, unsigned int element_nr); 48void *flex_array_get(struct flex_array *fa, unsigned int element_nr);
48 49
49#endif /* _FLEX_ARRAY_H */ 50#endif /* _FLEX_ARRAY_H */
diff --git a/lib/flex_array.c b/lib/flex_array.c
index 7baed2fc3bc8..b68f99be4080 100644
--- a/lib/flex_array.c
+++ b/lib/flex_array.c
@@ -207,6 +207,32 @@ int flex_array_put(struct flex_array *fa, unsigned int element_nr, void *src,
207} 207}
208 208
209/** 209/**
210 * flex_array_clear - clear element in array at @element_nr
211 * @element_nr: index of the position to clear.
212 *
213 * Locking must be provided by the caller.
214 */
215int flex_array_clear(struct flex_array *fa, unsigned int element_nr)
216{
217 int part_nr = fa_element_to_part_nr(fa, element_nr);
218 struct flex_array_part *part;
219 void *dst;
220
221 if (element_nr >= fa->total_nr_elements)
222 return -ENOSPC;
223 if (elements_fit_in_base(fa))
224 part = (struct flex_array_part *)&fa->parts[0];
225 else {
226 part = fa->parts[part_nr];
227 if (!part)
228 return -EINVAL;
229 }
230 dst = &part->elements[index_inside_part(fa, element_nr)];
231 memset(dst, 0, fa->element_size);
232 return 0;
233}
234
235/**
210 * flex_array_prealloc - guarantee that array space exists 236 * flex_array_prealloc - guarantee that array space exists
211 * @start: index of first array element for which space is allocated 237 * @start: index of first array element for which space is allocated
212 * @end: index of last (inclusive) element for which space is allocated 238 * @end: index of last (inclusive) element for which space is allocated