Hi ,
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
Code:
void my_kernel_function
{
char buf[1024] ;
}
which was giving me stack overflow error and the system hang. After referrring some document i replaced the statement using
Code:
void my_kernel_function
{
char * buf ;
buf = kmalloc(required_length, GFP_ATOMIC) ;
if(!buf)
{
// though this never happened
error handling
}
kfree(buf);
}
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.