On Wed, Jan 05, 2005 at 07:56:09 -0000, bunty wrote: > > Hello all, > While doing kernel module programming i come to know following aspects that we must not use in kernel modules > 1)#define MODULE > #define __KERNEL__ Right. They are defined by the build system as appropriate. > 2) dont open files in kernel modules Unless you have a _very_ good reason. Eg. quota does have a good reason and does open files. But most of the time having userland helper feed the data over a device, proc file or a netlink socket is a lot better, because you can change source or format etc. in the helper without modifying the kernel. Also kernel should not do any parsing -- that is a work for usermode helper (you can call_usermodehelper() if you need data on-demand). > 3) dont allow kernel modules to sleep What the hell is this NONSENSE about. You don't seem to understand the difference between an application, which always has at last one execution thread and a kernel module, which is just a bunch of functions that get called from various places in kernel. Now some of those functions will get called in a process context, either on behalf of a user-space process (when it does a syscall), or in a kernel thread. Such functions can sleep. But it's not the module that is put to sleep -- it's the task (schedulable entity). Other, or even the same, function from the module may execute in another task concurently. Another functions will be called in interrupt or softirq context. These may not sleep, because these contexts are not under control of the scheduler. It has to be noted, that there are many innocent-looking functions in kernel, that can sleep (eg. semaphores or memory allocation (except with GFP_ATOMIC flag)), so you must not call them in fuction called in interrupt/softirq context. If you don't understand what the above is all about, than I suggest you read some book about Linux kernel (eg. the Linux Device Drivers). ------------------------------------------------------------------------------- Jan 'Bulb' Hudec <bulb@xxxxxx>
Attachment:
signature.asc
Description: Digital signature