You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Improve the descriptions about reference count (#62)
The term "reference count" would be better than "use count."
In addition, the usage of module_refcount(THIS_MODULE) was appended
for the reference counter query.
Copy file name to clipboardExpand all lines: lkmpg.tex
+4-3Lines changed: 4 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -894,14 +894,15 @@ \subsection{Unregistering A Device}
894
894
Normally, when you do not want to allow something, you return an error code (a negative number) from the function which is supposed to do it.
895
895
With \cpp|cleanup_module| that's impossible because it is a void function.
896
896
However, there is a counter which keeps track of how many processes are using your module.
897
-
You can see what its value is by looking at the 3rd field of \verb|/proc/modules|.
897
+
You can see what its value is by looking at the 3rd field with the command \sh|cat /proc/modules| or \sh|sudo lsmod|.
898
898
If this number isn't zero, \sh|rmmod| will fail.
899
899
Note that you do not have to check the counter within \cpp|cleanup_module| because the check will be performed for you by the system call \cpp|sys_delete_module|, defined in \src{include/linux/syscalls.h}.
900
900
You should not use this counter directly, but there are functions defined in \src{include/linux/module.h} which let you increase, decrease and display this counter:
901
901
902
902
\begin{itemize}
903
-
\item\cpp|try_module_get(THIS_MODULE)|: Increment the use count.
904
-
\item\cpp|module_put(THIS_MODULE)|: Decrement the use count.
903
+
\item\cpp|try_module_get(THIS_MODULE)|: Increment the reference count of current module.
904
+
\item\cpp|module_put(THIS_MODULE)|: Decrement the reference count of current module.
905
+
\item\cpp|module_refcount(THIS_MODULE)|: Return the value of reference count of current module.
905
906
\end{itemize}
906
907
907
908
It is important to keep the counter accurate; if you ever do lose track of the correct usage count, you will never be able to unload the module; it's now reboot time, boys and girls.
0 commit comments