我刚开始学驱动,还不是太懂,今天写了个S5PC100的简单LED驱动,但在rmmod驱动时,class中对应驱动的目录不能清除,再次加载驱动时报错,报错信息如下:
/ # insmod led_driver.ko
------------[ cut here ]------------
WARNING: at fs/sysfs/dir.c:451 sysfs_add_one+0x64/0x84()
sysfs: cannot create duplicate filename '/class/class_led_driver'
Modules linked in: led_driver(+) [last unloaded: led_driver]
[<c002c130>] (unwind_backtrace+0x0/0xe0) from [<c003d2a8>] (warn_slowpath_common+0x4c/0x64)
[<c003d2a8>] (warn_slowpath_common+0x4c/0x64) from [<c003d340>] (warn_slowpath_fmt+0x2c/0x3c)
不知道这个和文件系统会不会有关系,文件系统是我自己做的,好像做的不是太完善。
init和exit代码如下:
static int __init led_init(void)
{
int i;
led_major = register_chrdev(0, "s5pc100_led_driver", &s5pc100_led_ops);
if(led_major < 0)
{
printk("register_chrdev error!\n");
goto err_led_init;
}
led_class = class_create(THIS_MODULE, "class_led_driver");
if(NULL == led_class)
{
printk("class_create error!\n");
goto err_led_init;
}
for(i=0; i<4; i++)
device_create(led_class, NULL, MKDEV(led_major, i), NULL, "LED%d", i+1);
return 0;
err_led_init:
if(led_major < 0)
return -1;
unregister_chrdev(led_major, "s5pc100_led_driver");
if(NULL == led_class)
return -1;
class_destroy(led_class);
return -1;
}
static void __exit led_exit(void)
{
int i;
for(i=0; i<4; i++);
device_destroy(led_class, MKDEV(led_major, i));
class_destroy(led_class);
unregister_chrdev(led_major, "s5pc100_led_driver");