I am new to linux device driver programming so perhaps my question is somewhat naïve.
This is in the scope of char devices, yet perhaps its relevant to other cases as well (??).
As I understand it so far, within the __init method of the module, all necessary initialization of the module must take place and once this function done – the module should be able to handle any request it gets from the kernel and/or user space application. Also, as part of the __init method our module needs to get a major number (assuming we allocate it dynamically) and then create the “respective” device file under the /dev directory. There are a couple of ways to do this.
1) The driver itself can print the newly assigned number and we can make the device file by hand.
2) The newly registered device will have an entry in /proc/devices, and we can either make the device file by hand or write a shell script to read the file in and make the device file.
3) We can have our driver make the device file using the mknod system call after a successful registration and rm during the call to cleanup_module.
Now as far as I see it, unless there is some piece of code in the __init method that “suspends” the termination of the __init method BEFORE we create the device file --> it means our module will potentially start receive requests WITHOUT the device file being ready , Isn’t it a problem (assuming we take the first or second approach) ?
static int major;
static struct file_operations fops = {
.owner = THIS_MODULE,
.read = dev_read,
.write = dev_write,
.open = dev_open,
.release = dev_release
};
static int __init myModuleInitMethod()
{
major = register_chardev(0, “myChaeDev”, &fops);
// some more initialization
// ...
// yet no creation of the device file, using mknod
} // myModuleInitMethod terminates and device file isn’t ready – problem ??
Feel free to note some other points to consider in case I did not mention them. Thanks,
Guy.