The most straightforward way to allocate memory is to use the kmalloc() function, and, to be on the safe side, it’s best to use routines that clear the allocated memory to zero, such as the kzalloc() function. On the other hand, if we need to allocate memory for an array, there are kmalloc_array() and kcalloc() dedicated functions.
Here are some snippets containing memory allocation kernel functions (and the relative kernel memory deallocation functions) as reported in the header file, linux/include/linux/slab.h:
/**
* kmalloc - allocate memory
* @size: how many bytes of memory are required.
* @flags: the type of memory to allocate.
...
*/
static __always_inline void *kmalloc(size_t size, gfp_t flags);
/**
* kzalloc - allocate memory. The memory is set to zero.
* @size: how many bytes of memory are required.
* @flags: the type of memory to allocate...