[FE training-materials-updates] Kernel slides: document devm_ functions for memory allocation

Michael Opdenacker michael.opdenacker at free-electrons.com
Tue Feb 4 23:08:45 CET 2014

Repository : git://git.free-electrons.com/training-materials.git

On branch  : master
Link       : http://git.free-electrons.com/training-materials/commit/?id=e96dfefe95ac6f86314ae4e05ba9fd4643aee8a4


commit e96dfefe95ac6f86314ae4e05ba9fd4643aee8a4
Author: Michael Opdenacker <michael.opdenacker at free-electrons.com>
Date:   Tue Feb 4 23:08:01 2014 +0100

    Kernel slides: document devm_ functions for memory allocation
    Signed-off-by: Michael Opdenacker <michael.opdenacker at free-electrons.com>


 .../kernel-driver-development-memory.tex           |   21 ++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)

diff --git a/slides/kernel-driver-development-memory/kernel-driver-development-memory.tex b/slides/kernel-driver-development-memory/kernel-driver-development-memory.tex
index 425c0ee..2b75a4c 100644
--- a/slides/kernel-driver-development-memory/kernel-driver-development-memory.tex
+++ b/slides/kernel-driver-development-memory/kernel-driver-development-memory.tex
@@ -330,8 +330,7 @@ kfree(work);
     \item Allocates memory for an array of \code{n} elements of
       \code{size} size, and zeroes its contents.
-  \item \mint{c}+void *krealloc(const void *p, size_t new_size,+
-    \mint{c}+gfp_t flags);+
+  \item {\footnotesize \mint{c}+void *krealloc(const void *p, size_t new_size, gfp_t flags);+}
     \item Changes the size of the buffer pointed by \code{p} to
       \code{new_size}, by reallocating a new buffer and copying the
@@ -342,6 +341,24 @@ kfree(work);
+  \frametitle{devm\_ kmalloc functions}
+  \begin{itemize}
+  \item Automatically free the allocated buffers when the 
+        corresponding device or module is unprobed.
+  \item Need to have a reference to a \kstruct{device}.
+  \item {\footnotesize \mint{c}+void *devm_kmalloc(struct device *dev, size_t size, int flags);+}
+  \item {\footnotesize \mint{c}+void *devm_kzalloc(struct device *dev, size_t size, int flags);+}
+  \item {\scriptsize \mint{c}+void *kcalloc(struct device *dev, size_t n, size_t size, gfp_t flags);+}
+  \item {\small \mint{c}+void *devm_kfree(struct device *dev, void *p);+}
+        \begin{itemize}
+        \item Useful to immediately free an allocated buffer
+        \end{itemize}
+  \end{itemize}
+  See \kerneldoc{driver-model/devres.txt} for details about managed
+  device resources.
   \frametitle{vmalloc Allocator}
   \item The \kfunc{vmalloc} allocator can be used to obtain virtually

More information about the training-materials-updates mailing list