红联Linux门户
Linux帮助

insmod自己编写的设备模块时,出现异常?

发布时间:2010-10-04 21:03:38来源:红联作者:308534826
小弟我用的内核版本是2.6.31版本的,其设备(还有个总线的程序没贴出)的程序代码如下:
#include
#include
#include
#include
#include

extern struct device my_bus;
extern struct bus_bype my_bus_type;

static void my_dev_release(struct device *dev)
{

}

struct device my_dev =
{
.bus = &my_bus_type,
.init_name = "my_dev",
.parent = &my_bus,
.release = my_dev_release,
};

static ssize_t mydev_show(struct device *dev,struct device_attribute *attr,char *buf)
{
return sprintf(buf,"%s\n","This is my device!");
}

DEVICE_ATTR(dev,S_IRUGO,mydev_show,NULL);

static int __init my_dev_init()
{
int ret = 0;

ret = device_register(&my_dev);//注册设备
if(ret)
return ret;
if(device_create_file(&my_dev,&dev_attr_dev))//设置设备属性
printk("<1>Create device file is errnor!\n");
return ret;
}

static void __exit my_dev_exit()
{
device_unregister(&my_dev);
}

module_init(my_dev_init);
module_exit(my_dev_exit);

MODULE_LICENSE("GPL");
编译完成后在板子上运行出现以下的异常:
[root@TX2440A /]# insmod lib/modules/2.6.31/my_bus.ko
[root@TX2440A /]# insmod my_dev.ko
------------[ cut here ]------------
WARNING: at lib/kref.c:43 kref_get+0x1c/0x40()
Modules linked in: my_dev(+) my_bus
[] (unwind_backtrace+0x0/0xd4) from [] (warn_slowpath_common+0x48/0x64)
[] (warn_slowpath_common+0x48/0x64) from [] (kref_get+0x1c/0x40)
[] (kref_get+0x1c/0x40) from [] (kobject_get+0x10/0x18)
[] (kobject_get+0x10/0x18) from [] (get_device+0x18/0x28)
[] (get_device+0x18/0x28) from [] (device_add+0x84/0x55c)
[] (device_add+0x84/0x55c) from [] (my_dev_init+0xc/0x3c [my_dev])
[] (my_dev_init+0xc/0x3c [my_dev]) from [] (do_one_initcall+0x60/0x1ac)
[] (do_one_initcall+0x60/0x1ac) from [] (sys_init_module+0xc0/0x1d8)
[] (sys_init_module+0xc0/0x1d8) from [] (ret_fast_syscall+0x0/0x2c)
---[ end trace 7a0b671d0c9f9420 ]---
Unable to handle kernel NULL pointer dereference at virtual address 00000020
pgd = c3b4c000
[00000020] *pgd=339b4031, *pte=00000000, *ppte=00000000
Internal error: Oops: 17 [#1]
Modules linked in: my_dev(+) my_bus
CPU: 0 Tainted: G W (2.6.31 #15)
PC is at sysfs_addrm_start+0x2c/0x9c
LR is at __mutex_lock_slowpath+0x200/0x214
pc : [] lr : [] psr: 40000013
sp : c3aabe90 ip : 22222222 fp : bf00c5a8
r10: 00000000 r9 : c3aaa000 r8 : c3aabecc
r7 : bf00c5a8 r6 : c3aabea0 r5 : c3aabea0 r4 : 00000000
r3 : 00000000 r2 : c0470318 r1 : 22222222 r0 : c380a600
Flags: nZcv IRQs on FIQs on Mode SVC_32 ISA ARM Segment user
Control: c000717f Table: 33b4c000 DAC: 00000015
Process insmod (pid: 1355, stack limit = 0xc3aaa270)
Stack: (0xc3aabe90 to 0xc3aac000)
be80: c3b03c98 c3aabea0 fffffff4 c00f387c
bea0: 00000000 00000000 00000000 00000000 bf00c5a8 bf00c5a0 c045a32c bf00f000
bec0: bf0067b8 c00f3910 c3802c68 c0165f4c bf00c5a8 c016600c 00000000 bf00c5a0
bee0: c045a32c bf00f000 00000000 c01664ec bf0067b8 c3aabf04 00000000 c01ab918
bf00: 00000000 bf0067b0 bf00c660 bf0067b0 bf00c5a8 c0165d84 c48a55e4 bf00c5a0
bf20: bf00c660 00000000 bf00c660 c045a32c bf00f000 00000000 c3aaa000 00000000
bf40: 00000002 bf00f00c 00000000 c00412d0 00000000 00000000 00000000 00008457
bf60: bf00c660 00000000 00000000 bf00c660 00000000 001defd8 c0041f48 00000000
bf80: 00000002 c00864e4 fffffffc c00aebcc 001defd8 00000000 bed74e98 bed74e98
bfa0: 00000080 c0041da0 00000000 bed74e98 001defd8 00008457 00194b54 00000000
bfc0: 00000000 bed74e98 bed74e98 00000080 00000000 00000071 bed74e94 00000002
bfe0: 00000069 bed747fc 0001d270 00008ed4 60000010 001defd8 3050b031 3050b431
[] (sysfs_addrm_start+0x2c/0x9c) from [] (create_dir+0x44/0xa0)
[] (create_dir+0x44/0xa0) from [] (sysfs_create_dir+0x38/0x58)
[] (sysfs_create_dir+0x38/0x58) from [] (kobject_add_internal+0xb8/0x194)
[] (kobject_add_internal+0xb8/0x194) from [] (kobject_add+0x54/0x70)
[] (kobject_add+0x54/0x70) from [] (device_add+0xb0/0x55c)
[] (device_add+0xb0/0x55c) from [] (my_dev_init+0xc/0x3c [my_dev])
[] (my_dev_init+0xc/0x3c [my_dev]) from [] (do_one_initcall+0x60/0x1ac)
[] (do_one_initcall+0x60/0x1ac) from [] (sys_init_module+0xc0/0x1d8)
[] (sys_init_module+0xc0/0x1d8) from [] (ret_fast_syscall+0x0/0x2c)
Code: eb086101 e59f2064 e1a03004 e5920000 (e5941020)
---[ end trace 7a0b671d0c9f9421 ]---
Segmentation fault
小弟是个新手,很多问题都不懂。自己找了半天也找不到原因,只好向各位大虾求救,帮忙解答。小弟在此谢过了!
文章评论

共有 1 条评论

  1. 308534826 于 2010-10-06 11:21:11发表:

    :0w223dc大家帮忙看看啊~~~