2023-11-08 22:11:44 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
|
|
|
|
#include <linux/log2.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include "darray.h"
|
|
|
|
|
2024-08-22 07:50:22 +00:00
|
|
|
int __bch2_darray_resize_noprof(darray_char *d, size_t element_size, size_t new_size, gfp_t gfp)
|
2023-11-08 22:11:44 +00:00
|
|
|
{
|
|
|
|
if (new_size > d->size) {
|
|
|
|
new_size = roundup_pow_of_two(new_size);
|
|
|
|
|
2024-08-22 07:50:22 +00:00
|
|
|
void *data = kvmalloc_array_noprof(new_size, element_size, gfp);
|
2023-11-08 22:11:44 +00:00
|
|
|
if (!data)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2024-06-21 20:29:32 +00:00
|
|
|
if (d->size)
|
|
|
|
memcpy(data, d->data, d->size * element_size);
|
2023-12-30 19:38:29 +00:00
|
|
|
if (d->data != d->preallocated)
|
|
|
|
kvfree(d->data);
|
2023-11-08 22:11:44 +00:00
|
|
|
d->data = data;
|
|
|
|
d->size = new_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|