I was reading the LKMPG ( See Section 4.1.4. Unregistering A Device ) and it wasn't clear to me when to use the try_module_get / module_put
functions. Some of the LKMPG examples use them, some don't.
To add to the confusion, try_module_get
appears 282 times in 193 files in the 2.6.24 source, yet in Linux Device Drivers ( LDD3 ) and Essential Linux Device Drivers, they appears in not even a single code example.
I thought maybe they were tied to the old register_chrdev
interface ( superseded in 2.6 by the cdev interface ), but they only appear together in the same files 8 times:
find -type f -name *.c | xargs grep -l try_module_get | sort -u | xargs grep -l register_chrdev | sort -u | grep -c .
So when is it appropriate to use these functions and are they tied to the use of a particular interface or set of circumstances?
Edit
I loaded the sched.c example from the LKMPG and tried the following experiment:
anon@anon:~/kernel-source/lkmpg/2.6.24$ tail /proc/sched -f &
Timer called 5041 times so far
[1] 14594
anon@anon:~$ lsmod | grep sched
sched 2868 1
anon@anon:~$ sudo rmmod sched
ERROR: Module sched is in use
This leads me to believe that the kernel now does it's own accounting and the gets / puts may be obsolete. Can anyone verify this?