When I try to use malloc
in a kernel module I get an error message from the compiler. My code:
res=(ListNode*)malloc(sizeof(ListNode));
<
You can't use libraries in the kernel. None whatsoever.
This means that ANY function you're calling in the kernel needs to be defined in the kernel. Linux does not define a malloc, hence you can't use it.
There is a memory allocator and a family of memory allocation functions. Read the kernel docs on the memory allocator for more information.
Incidentially, there are a few functions the kernel defines which are in the standard C library as well; this is for convenience.
It does, for instance, defined snprintf