1 // SPDX-License-Identifier: GPL-2.0
3 #include <linux/slab.h>
6 * Merge two NULL-terminated pointer arrays into a newly allocated
7 * array, which is also NULL-terminated. Nomenclature is inspired by
8 * memset_p() and memcat() found elsewhere in the kernel source tree.
10 void **__memcat_p(void **a
, void **b
)
15 /* count the elements in both arrays */
16 for (nr
= 0, p
= a
; *p
; nr
++, p
++)
18 for (p
= b
; *p
; nr
++, p
++)
20 /* one for the NULL-terminator */
23 new = kmalloc_array(nr
, sizeof(void *), GFP_KERNEL
);
27 /* nr -> last index; p points to NULL in b[] */
28 for (nr
--; nr
>= 0; nr
--, p
= p
== b
? &a
[nr
] : p
- 1)
33 EXPORT_SYMBOL_GPL(__memcat_p
);