Re: SMP kernel

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I can see few problems with these modules, I am addressing them as
follows, if somebody finds them incorrect, please correct it.

> Mod.h :
> 
> int mod_open(struct inode * , struct file *);
> int mod_release(struct inode * , struct file *);
> 
> wait_queue_head_t wait;

dont define wait queue head in .h, .h shud only include declerations
not definitions (its a better practice and will keep you out of many
problems). define things in .c not in .h

> 
> struct file_operations file_ops={
>        open:mod_open,
>        release:mod_release,
> };
> 
> Mod.c :
> 
> #define __KERNEL__
> #define MODULE
> 

if you are compiling your module for SMP define __SMP__ before
including and header file. Something like this

#ifdef CONFIG_SMP
#define __SMP__
#endif

> #include<linux/kernel.h>
> #include<linux/module.h>
> 
> #include<linux/init.h>
> 
> #include<linux/fs.h>
> #include<asm/current.h>
> 
> #include "mod.h"
> 
> int mod_open(struct inode * in, struct file * fi)
> {
> 
>   init_waitqueue_head(&wait);
>   printk("The process is goin to a sleep state \n");
>   interruptible_sleep_on(&wait);
> 
> return 0;
> 
> }
> 
> int mod_release(struct inode * in, struct file * fi)
> {
>  printk("This is the close thing \n");
> 
> return 0;
> }
> 
> int load_module(void)
> {
>   int res;
> 
>   res = register_chrdev(0,"mod",&file_ops);

check the value returned by register_chrdev() function, if it is < 0,
its an error and you should return error to insmod.
 
>   printk("char dev. registered %d \n",res);
>   printk("The module is loaded \n");
>   return 0;
> }
> 
> void unload_module(void)
> {
>   printk("The module is unloaded \n");

you need to unregister your character device while unloading the
module, if you dont do this, system might crash if you try to do
operation like open on device node after unloading, because the module
supporting it is not anymore in memory.


Same suggestions are also applicable to other module written by you.

One more thing, as your two modules intent to use the same wait queue,
you base module should export the wait queue head so that can be used
in your 2nd module and in 2nd module you should decleare that as
extern.

-gd

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/



[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux