char device driver 動態登記 cdev_init

作者: dongji0105 (dongji0105)   2015-06-27 20:45:58
各位好,小弟目前遇到一個error: implicit declaration of function ‘dev_init’
[-Werror=implicit-function-declaration]
程式碼如下(照著書本打的):
static int devone_init(void)
{
dev_t dev = MKDEV(devone_major, 0);
int alloc_ret = 0;
int major;
int cdev_err = 0;
// get major number
alloc_ret = alloc_chrdev_region(&dev, 0, devone_devs, DRIVER_NAME);
if(alloc_ret){
goto error;
}
devone_major = major = MAJOR(dev);
dev_init(&devone_cdev, &devone_fops);
devone_cdev.owner = THIS_MODULE;
cdev_err = cdev_add(&devone_cdev, MKDEV(devone_major, 0), devone_devs);
if(cdev_err){
goto error;
}
printk(KERN_ALERT "%s driver(major %d) installed.\n", DRIVER_NAME, major);
return 0;
error:
if(cdev_err == 0){
cdev_del(&devone_cdev);
}
if(alloc_ret == 0){
unregister_chrdev_region(dev, devone_devs);
}
return -1;
}
也有include <linux/cdev.h>
這是為什麼?
謝謝各位前輩
作者: wtchen (沒有存在感的人)   2015-06-28 02:23:00
你確定不是cdev_init?dev_init(&devone_cdev, &devone_fops); -> 這行
作者: dongji0105 (dongji0105)   2015-06-28 08:23:00
是這行啊!

Links booklink

Contact Us: admin [ a t ] ucptt.com