第一次insmod ko驱动,正常运行无异常,rmmod 后再insmod一次,就出现下面的异常,并且导致内核重启之后ko 也没法正常运行起来了,why?
<4>[ 371.040525] ------------[ cut here ]------------
<4>[ 371.040558] WARNING: at fs/sysfs/dir.c:455 sysfs_add_one+0x8c/0xc0()<4>[ 371.040580] sysfs: cannot create duplicate filename '/board_properties'
<4>[ 371.040623] [<c04433a4>] (unwind_backtrace+0x0/0xf8) from [<c047416c>] (warn_slowpath_common+0x4c/0x64)
<4>[ 371.040662] [<c047416c>] (warn_slowpath_common+0x4c/0x64) from [<c0474218>] (warn_slowpath_fmt+0x30/0x40)
<4>[ 371.040699] [<c0474218>] (warn_slowpath_fmt+0x30/0x40) from [<c05642f4>] (sysfs_add_one+0x8c/0xc0)
<4>[ 371.040739] [<c05642f4>] (sysfs_add_one+0x8c/0xc0) from [<c0564388>] (create_dir+0x60/0xbc)
<4>[ 371.040773] [<c0564388>] (create_dir+0x60/0xbc) from [<c0564494>] (sysfs_create_dir+0x84/0xf0)
<4>[ 371.040809] [<c0564494>] (sysfs_create_dir+0x84/0xf0) from [<c0611e00>] (kobject_add_internal+0x9c/0x1f4)
<4>[ 371.040847] [<c0611e00>] (kobject_add_internal+0x9c/0x1f4) from [<c0612224>] (kobject_add+0x4c/0x94)
<4>[ 371.040886] [<c0612224>] (kobject_add+0x4c/0x94) from [<c061240c>] (kobject_create_and_add+0x28/0x64)
<4>[ 371.040931] [<c061240c>] (kobject_create_and_add+0x28/0x64) from [<bf052404>] (goodix_ts_init+0x14/0xe0 [gt9xx])
<4>[ 371.040982] [<bf052404>] (goodix_ts_init+0x14/0xe0 [gt9xx]) from [<c04386f8>] (do_one_initcall+0xfc/0x164)
<4>[ 371.041028] [<c04386f8>] (do_one_initcall+0xfc/0x164) from [<c04a9fc8>] (sys_init_module+0xcd0/0x1a68)
<4>[ 371.041068] [<c04a9fc8>] (sys_init_module+0xcd0/0x1a68) from [<c043dfc0>] (ret_fast_syscall+0x0/0x30)
<4>[ 371.041100] ---[ end trace 6dc940aed50f2806 ]---
<3>[ 371.041126] kobject_add_internal failed for board_properties with -EEXIST, don't try to register things with the same name in the same directory.
<4>[ 371.041175] [<c04433a4>] (unwind_backtrace+0x0/0xf8) from [<c0611f40>] (kobject_add_internal+0x1dc/0x1f4)
<4>[ 371.041212] [<c0611f40>] (kobject_add_internal+0x1dc/0x1f4) from [<c0612224>] (kobject_add+0x4c/0x94)
<4>[ 371.041294] [<c0612224>] (kobject_add+0x4c/0x94) from [<c061240c>] (kobject_create_and_add+0x28/0x64)
<4>[ 371.041337] [<c061240c>] (kobject_create_and_add+0x28/0x64) from [<bf052404>] (goodix_ts_init+0x14/0xe0 [gt9xx])
<4>[ 371.041388] [<bf052404>] (goodix_ts_init+0x14/0xe0 [gt9xx]) from [<c04386f8>] (do_one_initcall+0xfc/0x164)
<4>[ 371.041428] [<c04386f8>] (do_one_initcall+0xfc/0x164) from [<c04a9fc8>] (sys_init_module+0xcd0/0x1a68)
<4>[ 371.041466] [<c04a9fc8>] (sys_init_module+0xcd0/0x1a68) from [<c043dfc0>] (ret_fast_syscall+0x0/0x30)
<4>[ 371.041500] kobject_create_and_add: kobject_add error: -17
<3>[ 371.041521] failed to create board_properties
问题找到了!这个应该是卸载时候没有删除一些东西造成的,board_properties重复了,并且sysfs: cannot create duplicate filename '/board_properties'这提示太明显了,原来是我在exit 函数没有卸载掉kobject_create_and_add 产生的kobject,在exit 函数加入kobject_put完美解决这个问题,不过触摸虚拟按键还是不能用,咋回事呢?是不是权限问题呢,然后把ko文件由0777 改成0644 ,重启后,居然虚拟按键也好了!哦哦哦,太爽了,最大的障碍解决了!
参考下面的代码解决了。
static struct kobject *example_kobj;
static int __init example_init(void)
{
int retval;
/*
* Create a simple kobject with the name of "kobject_example",
* located under /sys/kernel/
*
* As this is a simple directory, no uevent will be sent to
* userspace. That is why this function should not be used for
* any type of dynamic kobjects, where the name and number are
* not known ahead of time.
*/
example_kobj = kobject_create_and_add("kobject_example", kernel_kobj);
if (!example_kobj)
return -ENOMEM;
/* Create the files associated with this kobject */
retval = sysfs_create_group(example_kobj, &attr_group);
if (retval)
kobject_put(example_kobj);
return retval;
}
static void __exit example_exit(void)
{
kobject_put(example_kobj);
}
在insmod和rmmod KO驱动过程中遇到异常,导致内核重启后模块无法正常运行。问题根源在于exit函数未清除kobject。通过在exit函数中加入kobject_put解决了重复board_properties问题,但触摸虚拟按键仍无法使用。进一步调整ko文件权限从0777改为0644,成功修复问题并启用虚拟按键。参考代码展示了kobject创建和清理的方法。
1175

被折叠的 条评论
为什么被折叠?



