[问题] LKMPG chardev 为什么要用 module_put ?

楼主: b0920075 (Void)   2022-06-13 12:21:51
我自己解决了 ^^
================
我昨天在阅读现在新版的 lkmpg ,在其中一个章节有 character device 的 example
code :
https://sysprog21.github.io/lkmpg/#chardevc
前面 6.4 有提过:
Note that you don't have to check the counter within cleanup_module because
the check will be performed for you by the system call sys_delete_module,
defined in include/linux/syscall.h . You should not use this counter
directly but there are functions defined in include/linux/module.h which
that you increase, decrease and display the counter:
try_module_get(THIS_MODULE) : .........
module_put(THIS_MODULE) : .........
module_refcount(THIS_MODULE): .........
但是在 chardev.c 里面却在 device_open 里面用 try_module_get(THIS_MODULE) 去增
加 refcount ,在 device_release 里面用 module_put(THIS_MODULE)
说好的不推荐直接使用呢???
目前看过的 kernel module 的 code 好像也没有人呼叫过这些 function , kernel 应
该会帮忙 handle 这些 lkm 的 refcount ,不明白加这些的用意在干嘛....
作者: admon (睡梦中)   2022-06-13 12:40:00
黄字说不要用变量,要用函式。你英文不好。
作者: dragon121985 (Worldpeace)   2022-06-16 20:58:00
softdep可能是更好的选择?

Links booklink

Contact Us: admin [ a t ] ucptt.com