The main number tells you which driver processes the device file. An invalid number is used only by the driver itself to distinguish which device it is running on, just in case the driver is processing multiple devices.
Adding a driver to your system means registering it with the kernel. This is synonymous with assigning a large number during module initialization. You do this using the register_chrdev function defined by linux / fs.h.
int register_chrdev(unsigned int major, const char *name, struct file_operations *fops);
where unsigned int major is the main number you want to request, const char * name is the name of the device that will be displayed in / proc / devices and struct file_operations * fops is a pointer to the file_operations table for your driver. A negative return value means that registration failed. Please note that we did not pass the register_chrdev minor number. This is because the kernel does not care about the lowest number; only our driver uses it.
From here
source share