[問題] 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