]> git.sesse.net Git - bcachefs-tools-debian/blob - linux/darray.c
Disable pristine-tar option in gbp.conf, since there is no pristine-tar branch.
[bcachefs-tools-debian] / linux / darray.c
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * (C) 2022-2024 Kent Overstreet <kent.overstreet@linux.dev>
4  */
5
6 #include <linux/darray.h>
7 #include <linux/log2.h>
8 #include <linux/slab.h>
9
10 int __darray_resize_slowpath(darray_char *d, size_t element_size, size_t new_size, gfp_t gfp)
11 {
12         if (new_size > d->size) {
13                 new_size = roundup_pow_of_two(new_size);
14
15                 void *data = kvmalloc_array(new_size, element_size, gfp);
16                 if (!data)
17                         return -ENOMEM;
18
19                 memcpy(data, d->data, d->size * element_size);
20                 if (d->data != d->preallocated)
21                         kvfree(d->data);
22                 d->data = data;
23                 d->size = new_size;
24         }
25
26         return 0;
27 }