[BL training-materials-updates] kernel labs: improve memory management related instructions
Michael Opdenacker
michael.opdenacker at bootlin.com
Sun Nov 25 10:05:29 CET 2018
Repository : git://git.free-electrons.com/training-materials.git
On branch : master
Link : http://git.free-electrons.com/training-materials/commit/?id=1dfabfbba877244a49ae0fec360e59cbc15c1f30
>---------------------------------------------------------------
commit 1dfabfbba877244a49ae0fec360e59cbc15c1f30
Author: Michael Opdenacker <michael.opdenacker at bootlin.com>
Date: Sun Nov 25 10:05:29 2018 +0100
kernel labs: improve memory management related instructions
Signed-off-by: Michael Opdenacker <michael.opdenacker at bootlin.com>
>---------------------------------------------------------------
1dfabfbba877244a49ae0fec360e59cbc15c1f30
labs/kernel-i2c-input-interface/kernel-i2c-input-interface.tex | 6 ++----
labs/kernel-i2c-input-interface/private-data-alloc.c | 1 -
labs/kernel-serial-iomem/kernel-serial-iomem.tex | 6 ++++++
3 files changed, 8 insertions(+), 5 deletions(-)
diff --git a/labs/kernel-i2c-input-interface/kernel-i2c-input-interface.tex b/labs/kernel-i2c-input-interface/kernel-i2c-input-interface.tex
index 7303dc8..65ca0d3 100644
--- a/labs/kernel-i2c-input-interface/kernel-i2c-input-interface.tex
+++ b/labs/kernel-i2c-input-interface/kernel-i2c-input-interface.tex
@@ -150,10 +150,8 @@ Then allocate one such instead for each new device:
Note that we haven't seen kernel memory allocator routines and flags
yet.
-We haven't explained the \code{dev_*} logging routines yet either
-(they are basically used to tell which device a given log message is
-associated to). For the moment, just use the above code. You will get
-all the details later.
+Also note that here there's no need to write an "out of memory"
+message to the kernel log. That's already done by the memory subsystem.
Now implement the pointers that we need:
diff --git a/labs/kernel-i2c-input-interface/private-data-alloc.c b/labs/kernel-i2c-input-interface/private-data-alloc.c
index ed3ce1c..349f543 100644
--- a/labs/kernel-i2c-input-interface/private-data-alloc.c
+++ b/labs/kernel-i2c-input-interface/private-data-alloc.c
@@ -1,5 +1,4 @@
nunchuk = devm_kzalloc(&client->dev, sizeof(struct nunchuk_dev), GFP_KERNEL);
if (!nunchuk) {
- dev_err(&client->dev, "Failed to allocate memory\n");
return -ENOMEM;
}
diff --git a/labs/kernel-serial-iomem/kernel-serial-iomem.tex b/labs/kernel-serial-iomem/kernel-serial-iomem.tex
index 2cc5d1c..f0f8f57 100644
--- a/labs/kernel-serial-iomem/kernel-serial-iomem.tex
+++ b/labs/kernel-serial-iomem/kernel-serial-iomem.tex
@@ -143,6 +143,8 @@ So, add the below line to your code:
struct serial_dev *dev;
...
dev = devm_kzalloc(&pdev->dev, sizeof(struct serial_dev), GFP_KERNEL);
+if (!dev)
+ return -ENOMEM;
\end{verbatim}
You can now get a virtual address for your device's base physical
@@ -160,6 +162,10 @@ What's nice is that you won't ever have to release this resource,
neither in the \code{remove()} routine, nor if there are failures
in subsequent steps of the \code{probe()} routine.
+We haven't explained the \code{dev_*} logging routines yet.
+Before further explanations, they are basically used to tell which
+device a given log message is associated to.
+
Make sure that your updated driver compiles, loads and unloads well.
\section{Device initialization}
More information about the training-materials-updates
mailing list