I am writing a linux kernel module where i had to allocate large memory quite a few times in the module.
For eg. I was using statement like
char buf ;
which was giving me stack overflow error and the system hang. After referrring some document i replaced the statement using
char * buf ;
buf = kmalloc(required_length, GFP_ATOMIC) ;
// though this never happened
This fixed my problem.
but I dont find any difference between the dynamic allocation and my previous approach, since my kmalloc never failed and i am freeing the 'buf' only at the end of function.
Since i dont know the internals of kmalloc, if someone could find a reason for the happening please explain.