Hi I have tried to solve this problem for a few hours now and I am kinda running out of ideas. It's my first linux module, so please bear with me if the problem seems really trivial and obvious. I would really appreciate any help on this issue. I have attached the source code. I am trying to install my linux kernel module I am getting the following error: ############### ERROR: insmod queryDevice.o queryDevice.o: init_module: Device or resource busy Hint: insmod errors can be caused by incorrect module parameters, including invalid IO or IRQ parameters. You may find more information in syslog or the output from dmesg ONCE this error occurs I cannot do cat /proc/devices anymore (doing so results in Segmentation fault) lsmod still works (but doesn't list my module that I tried to install) Also I have to reboot the machine since, doing insmod again just gives the same problem and also the deviceMajorNum is reduced by everytime (like 254, 253, 252 etc.,) and I cannot trust the insmod after the first error. ############### +++++++++++ Linux Version: # uname -a Linux dhcp-293-19 2.4.18-14 #1 Wed Sep 4 13:35:50 EDT 2002 i686 i686 i386 GNU/Linux +++++++++ ********** dmesg output: (relevant lines) After pci_present After register_chrdev After hostQueryRegisterSymbols:254 ********** The "register_chrdev" call in "hostQueryModuleInit" function messes up things as I found out so far, since commenting it out seems to make "insmod" and "rmmod" work. But it seems pretty harmless. Am I missing something ? I am using a dynamic major number assignment (like the O'Reilly book says) Thank you very much for your help. Vijay
#ifndef __KERNEL__ #define __KERNEL__ #endif #ifndef MODULE #define MODULE #endif // ... OS include files #include <linux/module.h> #include <linux/kernel.h> #include <linux/init.h> #include <linux/ioctl.h> #include <linux/slab.h> #include <linux/fs.h> #include <linux/errno.h> #include <linux/types.h> #include <linux/pci.h> #include <asm/uaccess.h> #include <asm/io.h> // ... Local declarations // ... Global variable declarations // ... Static variable declarations static int queryMajorNum; static int queryDevRegistered = 0; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // ... Constants // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - MODULE_AUTHOR("Vijay Venkata"); MODULE_SUPPORTED_DEVICE("All Devices on pcibus with a vendorId and deviceId"); MODULE_DESCRIPTION("Provides Query mechanism to get slot information for a" "given vendorId,deviceId tuple"); MODULE_LICENSE("GPL"); // Just to make the license warning go away on insmod // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // ... Data Types // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // ... The Query Device typedef struct { // ... Nothing Device specific }query_Dev; // ... The pci device static struct pci_dev* pPciDev = NULL; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /* ; ; .FUNCTION: ; ; .NOTES: ; */ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //static void hostQueryRegisterSymbols ( void ) { EXPORT_NO_SYMBOLS; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // ... Device Functions // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /* ; ; .FUNCTION: ; ; .NOTES: ; */ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //static int queryDevice_open ( struct inode *inode, struct file *filp ) { // ... Do nothing return 0; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /* ; ; .FUNCTION: ; ; .NOTES: ; */ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //static int queryDevice_close ( struct inode *inode, struct file *filp ) { // ... Do nothing return 0; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // ... Device File Operations // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // ... The file operations on this device struct file_operations queryDevice_fops = { open: queryDevice_open, release: queryDevice_close, owner: THIS_MODULE, }; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // ... Module Entry/Exit Points // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /* ; ; .FUNCTION: ; ; .NOTES: ; */ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - int hostQueryModuleInit ( void ) { if (!pci_present ()) { printk ( KERN_WARNING "%s.%d::No pci... Aborting.\n", __FILE__, __LINE__ ); return -1; } printk ( KERN_INFO "After pci_present\n" ); // ... Get dynamic major number from kernel queryMajorNum = register_chrdev (0, "queryd", &queryDevice_fops); printk ( KERN_INFO "After register_chrdev\n" ); if (queryMajorNum < 0) { printk ( KERN_ERR "%s.%d::register_chrdev(%s) returned (%d)...\n", __FILE__, __LINE__, "queryd", queryMajorNum ); return queryMajorNum; } queryDevRegistered = 1; //hostQueryRegisterSymbols (); printk ( KERN_INFO "After hostQueryRegisterSymbols:%u \n", queryMajorNum ); return queryMajorNum; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /* ; ; .FUNCTION: ; ; .NOTES: ; */ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void hostQueryModuleUninit ( void ) { if (queryDevRegistered) { printk ( KERN_INFO "%s.%d::Unregistering host query Device ...\n", __FILE__, __LINE__ ); queryDevRegistered = 0; unregister_chrdev (queryMajorNum, "queryd"); } } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // ... Define the Entry/Exit points for this module // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - module_init(hostQueryModuleInit); module_exit(hostQueryModuleUninit); // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // ... end of file