2023-11-09 06:11:44 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
|
|
|
|
#include <linux/log2.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include "darray.h"
|
|
|
|
|
2023-12-31 03:38:29 +08:00
|
|
|
int __bch2_darray_resize(darray_char *d, size_t element_size, size_t new_size, gfp_t gfp)
|
2023-11-09 06:11:44 +08:00
|
|
|
{
|
|
|
|
if (new_size > d->size) {
|
|
|
|
new_size = roundup_pow_of_two(new_size);
|
|
|
|
|
2023-11-17 08:44:48 +08:00
|
|
|
void *data = kvmalloc_array(new_size, element_size, gfp);
|
2023-11-09 06:11:44 +08:00
|
|
|
if (!data)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2023-11-17 08:44:48 +08:00
|
|
|
memcpy(data, d->data, d->size * element_size);
|
2023-12-31 03:38:29 +08:00
|
|
|
if (d->data != d->preallocated)
|
|
|
|
kvfree(d->data);
|
2023-11-09 06:11:44 +08:00
|
|
|
d->data = data;
|
|
|
|
d->size = new_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|