在linux驱动中,通常都会使用module_init函数加载模块。比如SPI驱动中:
static int __init spidev_init(void)
{
int status;
/* Claim our 256 reserved device numbers. Then register a class
* that will key udev/mdev to add/remove /dev nodes. Last, register
* the driver which manages those device numbers.
*/
BUILD_BUG_ON(N_SPI_MINORS > 256);//如果条件为真,则引起一个编译错误
status = register_chrdev(SPIDEV_MAJOR, "spi", &spidev_fops);//注册驱动
if(status < 0)
return status;