rmmod: remove 'led': Device or resource busy解决办法

问题:

real6410开发板,使用insmod led.ko命令安装led驱动,然后使用命令rmmod led卸载led模块时遇到错误提示:

rmmod: remove 'led': Device or resource busy

解决办法:

1. 原因在于led驱动程序中没有用宏module_exit()实现模块被移除的功能。

在led.c中添加了real_leds_exit()函数,重新make,生成驱动文件led.ko。

static void __exit real_leds_exit(void) {

    printk("REAL_LEDS is released.\n");
}

重启目标板,使用insmod led.ko可以正确加载驱动,通过rmmod led删除驱动时,提示找不到文件led.ko,

将驱动文件led.ko拷贝到目录/lib/modules/2.6.28.6/中,再次删除驱动,就OK了。


但是,使用insmod led.ko再次加载驱动时,提示错误信息

[root@Real6410 leddriver]# insmod led.ko 
------------[ cut here ]------------
WARNING: at fs/sysfs/dir.c:462 sysfs_add_one+0x34/0x48()
sysfs: duplicate filename 'led_class' can not be created
Modules linked in: led(+) unifi_sdio [last unloaded: led]
[] (dump_stack+0x0/0x14) from [] (warn_slowpath+0x64/0x80)
[] (warn_slowpath+0x0/0x80) from [] (sysfs_add_one+0x34/0x48)
 r3:cf4e57f0 r2:c04ebcef
 r6:cf06e308 r5:cf78a360 r4:ffffffef
[] (sysfs_add_one+0x0/0x48) from [] (create_dir+0x58/0xa4)
 r5:cf78a360 r4:cf6f3d08
[] (create_dir+0x0/0xa4) from [] (sysfs_create_dir+0x44/0x64)
 r8:cf008348 r7:cf818740 r6:bf05b700 r5:cf06e308 r4:cf06e308
[] (sysfs_create_dir+0x0/0x64) from [] (kobject_add_internal+0xf4/0x1c8)
 r4:cf06e308
[] (kobject_add_internal+0x0/0x1c8) from [] (kset_register+0x28/0x44)
 r9:cf6f2000 r8:c002df88 r7:cf818740 r6:bf05b700 r5:cf06e308
r4:cf06e300
[] (kset_register+0x0/0x44) from [] (__class_register+0xb0/0x180)
 r5:00000000 r4:cf06e300
[] (__class_register+0x0/0x180) from [] (__class_create+0x44/0x6c)
 r9:cf6f2000 r8:c002df88 r7:bf05b5c0 r6:bf05b700 r5:bf05b0bd
r4:cf818740
[] (__class_create+0x0/0x6c) from [] (real_leds_init+0x60/0xa0 [led])
 r7:00000000 r6:bf05b0b4 r5:cf8186c0 r4:bf05b5c0
[] (real_leds_init+0x0/0xa0 [led]) from [] (do_one_initcall+0x54/0x180)
 r6:bf05e000 r5:bf05b5c0 r4:00000d4f
[] (do_one_initcall+0x0/0x180) from [] (sys_init_module+0x98/0x188)
 r7:00000000 r6:000b5038 r5:bf05b5c0 r4:00000d4f
[] (sys_init_module+0x0/0x188) from [] (ret_fast_syscall+0x0/0x2c)
 r7:00000080 r6:beb1ec78 r5:00000000 r4:00000000
---[ end trace bea89d483ae3e424 ]---
kobject_add_internal failed for led_class with -EEXIST, don't try to register things with the same name in the same directory.
[] (dump_stack+0x0/0x14) from [] (kobject_add_internal+0x180/0x1c8)
[] (kobject_add_internal+0x0/0x1c8) from [] (kset_register+0x28/0x44)
 r9:cf6f2000 r8:c002df88 r7:cf818740 r6:bf05b700 r5:cf06e308
r4:cf06e300
[] (kset_register+0x0/0x44) from [] (__class_register+0xb0/0x180)
 r5:00000000 r4:cf06e300
[] (__class_register+0x0/0x180) from [] (__class_create+0x44/0x6c)
 r9:cf6f2000 r8:c002df88 r7:bf05b5c0 r6:bf05b700 r5:bf05b0bd
r4:cf818740
[] (__class_create+0x0/0x6c) from [] (real_leds_init+0x60/0xa0 [led])
 r7:00000000 r6:bf05b0b4 r5:cf8186c0 r4:bf05b5c0
[] (real_leds_init+0x0/0xa0 [led]) from [] (do_one_initcall+0x54/0x180)
 r6:bf05e000 r5:bf05b5c0 r4:00000d4f
[] (do_one_initcall+0x0/0x180) from [] (sys_init_module+0x98/0x188)
 r7:00000000 r6:000b5038 r5:bf05b5c0 r4:00000d4f
[] (sys_init_module+0x0/0x188) from [] (ret_fast_syscall+0x0/0x2c)
 r7:00000080 r6:beb1ec78 r5:00000000 r4:00000000
REAL_LEDS initialized.

显然,是加载驱动时通过class_create()和device_create()添加的led_class等资源未被释放所导致。

在函数real_leds_exit()中添加释放资源的语句,

static void __exit real_leds_exit(void) {
    device_destroy(led_class, devid);
    class_destroy(led_class);
    printk("REAL_LEDS is released.\n");
}

重新编译生成驱动,重启目标板,加载驱动和卸载驱动就正常了。


问题解决。


你可能感兴趣的:(嵌入式linux,linux驱动)