]> git.sesse.net Git - bcachefs-tools-debian/blob - libbcachefs/darray.c
Upload to experimental
[bcachefs-tools-debian] / libbcachefs / darray.c
1 // SPDX-License-Identifier: GPL-2.0
2
3 #include <linux/log2.h>
4 #include <linux/slab.h>
5 #include "darray.h"
6
7 int __bch2_darray_resize(darray_void *d, size_t element_size, size_t new_size, gfp_t gfp)
8 {
9         if (new_size > d->size) {
10                 new_size = roundup_pow_of_two(new_size);
11
12                 void *data = krealloc_array(d->data, new_size, element_size, gfp);
13                 if (!data)
14                         return -ENOMEM;
15
16                 d->data = data;
17                 d->size = new_size;
18         }
19
20         return 0;
21 }