#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
[
[
[
[
[
[
[
[
[
---[ 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 : [
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
[
[
[
[
[
[
[
[
[
Code: eb086101 e59f2064 e1a03004 e5920000 (e5941020)
---[ end trace 7a0b671d0c9f9421 ]---
Segmentation fault
小弟是个新手,很多问题都不懂。自己找了半天也找不到原因,只好向各位大虾求救,帮忙解答。小弟在此谢过了!
308534826 于 2010-10-06 11:21:11发表:
:0w223dc大家帮忙看看啊~~~