Skip to content

Commit 432f007

Browse files
committed
Introduce cleveref package for cross-references
Introduce the 'cleveref' package to the document. This package allows for intelligent cross-referencing that automatically includes the reference type (e.g., "Section" or "Figure"). The change replaces all instances of \ref{...} with \Cref{...}. This improves document readability and simplifies maintenance by removing the need for manual text prefixes like "Section" or "Figure" before a reference. This aligns with contributor suggestions to adopt cleveref for better maintenance of cross-references across the document. Signed-off-by: Chia-Hao Chiu <[email protected]>
1 parent 39bc1a2 commit 432f007

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

lkmpg.tex

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
% citation
2626
\usepackage{cite}
2727
\usepackage[colorlinks,citecolor=green]{hyperref}
28+
\usepackage{cleveref}
2829

2930
\usepackage{xcolor}
3031
\hypersetup{
@@ -180,7 +181,7 @@ \subsection{Before We Begin}
180181
This output is \emph{not} automatically displayed on any console or terminal.
181182
To view kernel module messages, you must use \sh|dmesg| to read the kernel log ring buffer,
182183
or check the systemd journal with \sh|journalctl -k| for kernel messages.
183-
Refer to \ref{sec:helloworld} for more information.
184+
Refer to \Cref{sec:helloworld} for more information.
184185
The terminal or environment from which you load the module does not affect where the output goes—it always goes to the kernel log.
185186
\item SecureBoot.
186187
Numerous modern computers arrive pre-configured with UEFI SecureBoot enabled—an essential security standard ensuring booting exclusively through trusted software endorsed by the original equipment manufacturer.
@@ -411,7 +412,7 @@ \subsection{The Simplest Module}
411412
Actually, things have changed starting with kernel 2.3.13.
412413
% TODO: adjust the section anchor
413414
You can now use whatever name you like for the start and end functions of a module,
414-
and you will learn how to do this in Section \ref{hello_n_goodbye}.
415+
and you will learn how to do this in \Cref{sec:hello_n_goodbye}.
415416
In fact, the new method is the preferred method.
416417
However, many people still use \cpp|init_module()| and \cpp|cleanup_module()| for their start and end functions.
417418
@@ -421,7 +422,7 @@ \subsection{The Simplest Module}
421422
422423
Lastly, every kernel module needs to include \verb|<linux/module.h>|.
423424
% TODO: adjust the section anchor
424-
We needed to include \verb|<linux/printk.h>| only for the macro expansion for the \cpp|pr_alert()| log level, which you'll learn about in Section \ref{sec:printk}.
425+
We needed to include \verb|<linux/printk.h>| only for the macro expansion for the \cpp|pr_alert()| log level, which you'll learn about in \Cref{sec:printk}.
425426
426427
\begin{enumerate}
427428
\item A point about coding style.
@@ -459,7 +460,7 @@ \subsection{The Simplest Module}
459460
\end{enumerate}
460461
461462
\subsection{Hello and Goodbye}
462-
\label{hello_n_goodbye}
463+
\label{sec:hello_n_goodbye}
463464
In early kernel versions you had to use the \cpp|init_module| and \cpp|cleanup_module| functions, as in the first hello world example,
464465
but these days you can name those anything you want by using the \cpp|module_init| and \cpp|module_exit| macros.
465466
These macros are defined in \src{include/linux/module.h}.
@@ -1013,7 +1014,7 @@ \subsection{The file\_operations Structure}
10131014
So, we can safely implement those operations without unnecessary locking.
10141015

10151016
Additionally, since Linux v5.6, the \cpp|proc_ops| structure was introduced to replace the use of the \cpp|file_operations| structure when registering proc handlers.
1016-
See more information in the \ref{sec:proc_ops} section.
1017+
See more information in the \Cref{sec:proc_ops}.
10171018

10181019
\subsection{The file structure}
10191020
\label{sec:file_struct}
@@ -1098,7 +1099,7 @@ \subsection{Registering A Device}
10981099
int cdev_add(struct cdev *p, dev_t dev, unsigned count);
10991100
\end{code}
11001101

1101-
To find an example using the interface, you can see \verb|ioctl.c| described in section \ref{sec:device_files}.
1102+
To find an example using the interface, you can see \verb|ioctl.c| described in \Cref{sec:device_files}.
11021103

11031104
\subsection{Unregistering A Device}
11041105
\label{sec:unregister_device}
@@ -1147,7 +1148,7 @@ \subsection{chardev.c}
11471148
Therefore, a solution is to enforce exclusive access.
11481149
We use atomic Compare-And-Swap (CAS) to maintain the states, \cpp|CDEV_NOT_USED| and \cpp|CDEV_EXCLUSIVE_OPEN|, to determine whether the file is currently opened by someone or not.
11491150
CAS compares the contents of a memory location with the expected value and, only if they are the same, modifies the contents of that memory location to the desired value.
1150-
See more concurrency details in the \ref{sec:synchronization} section.
1151+
See more concurrency details in the \Cref{sec:synchronization}.
11511152

11521153
\samplec{examples/chardev.c}
11531154

@@ -1272,7 +1273,7 @@ \subsection{Manage /proc file with seq\_file}
12721273
BE CAREFUL: when a sequence is finished, another one starts.
12731274
That means that at the end of function \cpp|stop()|, the function \cpp|start()| is called again.
12741275
This loop finishes when the function \cpp|start()| returns \cpp|NULL|.
1275-
You can see a scheme of this in the Figure~\ref{img:seqfile}.
1276+
You can see a scheme of this in the \Cref{img:seqfile}.
12761277

12771278
\begin{figure}[h]
12781279
\center
@@ -1429,7 +1430,7 @@ \section{Talking To Device Files}
14291430
For more information, consult the kernel source tree at \src{Documentation/userspace-api/ioctl/ioctl-number.rst}.
14301431

14311432
Also, we need to be careful that concurrent access to the shared resources will lead to the race condition.
1432-
The solution is using atomic Compare-And-Swap (CAS), which we mentioned at \ref{sec:chardev_c} section, to enforce the exclusive access.
1433+
The solution is using atomic Compare-And-Swap (CAS), which we mentioned at \Cref{sec:chardev_c}, to enforce the exclusive access.
14331434

14341435
\samplec{examples/chardev2.c}
14351436

@@ -1827,7 +1828,7 @@ \section{Replacing Print Macros}
18271828
\label{sec:print_macros}
18281829
\subsection{Replacement}
18291830
% FIXME: cross-reference
1830-
In Section \ref{sec:preparation}, it was noted that the X Window System and kernel module programming are not conducive to integration.
1831+
In \Cref{sec:preparation}, it was noted that the X Window System and kernel module programming are not conducive to integration.
18311832
This remains valid during the development of kernel modules.
18321833
However, in practical scenarios, the necessity emerges to relay messages to the tty (teletype) originating the module load command.
18331834

@@ -1931,7 +1932,7 @@ \subsection{GPIO}
19311932

19321933
\subsection{Control the LED's on/off state}
19331934
\label{sec:gpio_led}
1934-
In Section \ref{sec:device_files}, we learned how to communicate with device files.
1935+
In \Cref{sec:device_files}, we learned how to communicate with device files.
19351936
Therefore, we will further use device files to control the LED on and off.
19361937

19371938
In the implementation, a pull-down resistor is used.
@@ -2007,7 +2008,7 @@ \section{Scheduling Tasks}
20072008
It is possible that in future tasklets may be replaced by \textit{threaded IRQs}.
20082009
However, discussion about that has been ongoing since 2007 (\href{https://lwn.net/Articles/239633}{Eliminating tasklets} and \href{https://lwn.net/Articles/960041/}{The end of tasklets}),
20092010
so expecting immediate changes would be unwise.
2010-
See the section \ref{sec:irq} for alternatives that avoid the tasklet debate.
2011+
See the \Cref{sec:irq} for alternatives that avoid the tasklet debate.
20112012

20122013
\subsection{Tasklets}
20132014
\label{sec:tasklet}
@@ -2210,7 +2211,7 @@ \section{Virtual Input Device Driver}
22102211
And, event injection is done through a \verb|/dev| node.
22112212
The device name will be used by the userland to export a new virtual input device.
22122213

2213-
The \cpp|class_attribute| structure is similar to other attribute types we talked about in section \ref{sec:sysfs}:
2214+
The \cpp|class_attribute| structure is similar to other attribute types we talked about in \Cref{sec:sysfs}:
22142215

22152216
\begin{code}
22162217
struct class_attribute {

0 commit comments

Comments
 (0)