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 imagine it like a three step process:
User space library - malloc()
System call - brk()
Inside Kernel - kmalloc/vmalloc/gfp etc routines of memory manager
So If you are already at step 3, writing kernel module, then going back wouldn't make sense. So you need to use the kernel routines only for memory allocation.