there seems to be a problem with kernel version 2.4-18, regarding the displaying of registered char devices. If i register a module which registers itself with an unused major number (200 in the below case)and the file_operations table being NULL , i don't see the device major number and the corresponding name "sleeper" when i "cat /proc/devices".
/* init_module shown below */
#define MAJOR_NUMBER 200 int
init_module(void)
{ int ret ; ret = register_chrdev(MAJOR_NUMBER,"sleeper",NULL);
if(ret < 0)
{
printk("<1> Could not register device \n");
return 1;
}
printk("<1> SLEEPER registered successfully \n"); return 0;
}
i followed up the callback which gets called when the /proc/devices is read , whichled me to int get_device_list(char * page) in fs/devices.c.
There, i saw that it wasn't adding to the display buffer , those module names whosefile_operations table was NULL. And if someone, now insmod'ed a module which inturnregisters a device major number 200 (after looking at /proc/devices and assuming no other module is using that device major number ) , it would overwrite my modules file_operations(which is NULL) and name which is "sleeper", with its f_ops and
name in :
static struct device_struct chrdevs[MAX_CHRDEV];
<snip> (from fs/devices.c)
static struct device_struct chrdevs[MAX_CHRDEV];
int get_device_list(char * page) { int i; int len;
len = sprintf(page, "Character devices:\n"); read_lock(&chrdevs_lock); for (i = 0; i < MAX_CHRDEV ; i++) { //if (chrdevs[i].fops) { // ORIGINAL CODE if (chrdevs[i].fops || chrdevs[i].name ) { // changed by me len += sprintf(page+len, "%3d %s\n", i, chrdevs[i].name); } } read_unlock(&chrdevs_lock); len += get_blkdev_list(page+len); return len; }
</snip>
To conclude, it doesnt make sense to register a char device without any file_op's defined on it (or does it ??? ) , still, if someone using it for testing purposes might get confused with such a situation, where /proc/devices doesnt show the module registered with a major number, since f_ops was NULL.
Comments welcome.
cheers, Amith
PS: After making the above changes and re-compiling the kernel , i could see my module registered with the major number 200.
And i would like to know where , such observations can be reported or whether they were reported earlier.
-- Kernelnewbies: Help each other learn about the Linux kernel. Archive: http://mail.nl.linux.org/kernelnewbies/ FAQ: http://kernelnewbies.org/faq/