当前位置: 技术问答>linux和unix
linux字符驱动insmod出现错误
来源: 互联网 发布时间:2017-03-03
本文导语: linux字符驱动insmod出现如下错误: BUG: unable to handle kernel NULL pointer dereference at 00000014 关键代码: struct mem_dev { char *data; unsigned long size; }; /*include semaphore ,cdev */ struct scull_dev //我自己定义的一...
linux字符驱动insmod出现如下错误:
BUG: unable to handle kernel NULL pointer dereference at 00000014
关键代码:
dmesg调试结果:
[ 210.151746] alloc register successfully.
[ 210.160767] 1111
[ 210.161425] BUG: unable to handle kernel NULL pointer dereference at 00000014
[ 210.161655] IP: [] cdev_init+0x23/0x50
其他信息:
BUG: unable to handle kernel NULL pointer dereference at 00000014
关键代码:
struct mem_dev
{
char *data;
unsigned long size;
};
/*include semaphore ,cdev
*/
struct scull_dev //我自己定义的一种字符设备,问题出自在各个?
但LDD上面写的可以将cdev结构嵌入到自己的设备特定结构中啊
{
struct mem_dev *mem_devp;
struct semaphore sem;
struct cdev cdev;
};
struct scull_dev *dev;
/*setup cdev*/
printk("1111n"); //执行完这一行后出错
cdev_init(&dev->cdev, &scull_fops); //问题就出现在这一行
printk("2222n");
dev->cdev.owner = THIS_MODULE;
printk("3333n");
dev->cdev.ops = &scull_fops; //relate file_operations
printk("4444n");
if ((ret = cdev_add(&dev->cdev, devt, 1))) //acknowledge kernel
{
printk(KERN_NOTICE "Error %d adding scull.n", ret);
return -1;
}
else
printk("scull register success.n");
dmesg调试结果:
[ 210.151746] alloc register successfully.
[ 210.160767] 1111
[ 210.161425] BUG: unable to handle kernel NULL pointer dereference at 00000014
[ 210.161655] IP: [] cdev_init+0x23/0x50
其他信息:
|
因为你没有为struct scull_dev *dev分配空间,要么你就用kmalloc分配
struct scull_dev *dev = kmalloc(sizeof(struct scull_dev ), GFP_KERNEL)
cdev_init(&dev->cdev, &scull_fops);
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。