[bootlin/training-materials updates] master: Kernel labs: add alternative coding option (6168853b)

Michael Opdenacker michael.opdenacker at bootlin.com
Wed Oct 21 05:59:25 CEST 2020

Repository : https://github.com/bootlin/training-materials
On branch  : master
Link       : https://github.com/bootlin/training-materials/commit/6168853bd78d2c2a2bed9095a22f4e361199328e


commit 6168853bd78d2c2a2bed9095a22f4e361199328e
Author: Michael Opdenacker <michael.opdenacker at bootlin.com>
Date:   Tue Oct 20 17:34:52 2020 +0200

    Kernel labs: add alternative coding option
    Signed-off-by: Michael Opdenacker <michael.opdenacker at bootlin.com>


 labs/kernel-serial-output/kernel-serial-output.tex | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/labs/kernel-serial-output/kernel-serial-output.tex b/labs/kernel-serial-output/kernel-serial-output.tex
index e52e59c0..d2cf6f55 100644
--- a/labs/kernel-serial-output/kernel-serial-output.tex
+++ b/labs/kernel-serial-output/kernel-serial-output.tex
@@ -102,7 +102,7 @@ from the \code{miscdevice} structure itself, accessible through the
 At the time we registered our {\em misc} device, we didn't keep any
 pointer to the \code{serial_dev} structure. However, as the
-\code{miscdevice} structure is accessible through
+\kstruct{miscdevice} structure is accessible through
 \code{file->private_data}, and is a member of the
 \code{serial_dev} structure, we can use a magic macro to compute
 the address of the parent structure:
@@ -115,10 +115,17 @@ struct serial_dev *dev =
 See \url{https://radek.io/2012/11/10/magical-container_of-macro/}
 for interesting implementation details about this macro.
-This wouldn't have been possible if the \code{miscdevice} structure
+This wouldn't have been possible if the \kstruct{miscdevice} structure
 was allocated separately and was just referred to by a pointer in
 \code{serial_dev}, instead of being a member of it.
+Another possibility, but more complicated, would have been to access the
+\code{parent} device pointer in \kstruct{miscdevice}, which then through
+the \kfunc{platform_get_drvdata} function would
+have given us access to the \code{serial_dev} structure containing the
+virtual address of the device. There are always multiple possibilities
+in kernel programming!
 Now, add code that copies (in a secure way) each character from the
 user space buffer to the UART device.

More information about the training-materials-updates mailing list