Linux Today: Linux News On Internet Time.

The Kernel Newbie Corner: Loadable Kernel Modules, Coming and Going

Jul 08, 2009, 19:32 (0 Talkback[s])
(Other stories by Rob Day)

[ Thanks to LinuxScribe for this link. ]

"Now, the purpose of a module's entry and exit routines is simple: it's your job to invoke everything that needs to happen upon module loading (allocating memory, registering devices, etc.), as well as module unloading (returning memory, unregistering devices, etc.), and here's the most important part: You have to clean up after yourself completely.

"Let me say that again, with feeling: Whatever you choose to do in a module's entry routine must be explicitly undone upon exit. Unlike what you might be used to in user space programming, you can't leave open files lying around or space dynamically allocated, knowing that someone is going to tidy up after you when your program eventually terminates. This is kernel space programming--no one is there to pick up after you. If you forget to deallocate some space that was dynamically allocated with, say, kmalloc(), then you've just introduced a memory leak, and other kernel programmers will not look kindly upon that."

Complete Story

Related Stories: