[U-Boot] [PATCH] Move malloc_cache_aligned() to malloc.h

Simon Glass sjg at chromium.org
Sat Aug 29 16:54:42 CEST 2015


At present malloc.h is included everywhere since it recently was added to
common.h in this commit:

   4519668 mtd/nand/ubi: assortment of alignment fixes

This seems wasteful and unnecessary. We have been trying to trim down
common.h and put separate functions into separate header files and that
change goes in the opposite direction.

Move malloc_cache_aligned() to malloc.h so that this can be avoided.

Signed-off-by: Simon Glass <sjg at chromium.org>
---

 fs/ubifs/super.c |  2 ++
 include/common.h |  9 ---------
 include/malloc.h | 12 ++++++++++++
 lib/zlib/zutil.c |  4 +++-
 4 files changed, 17 insertions(+), 10 deletions(-)

diff --git a/fs/ubifs/super.c b/fs/ubifs/super.c
index 0bf52db..74edff1 100644
--- a/fs/ubifs/super.c
+++ b/fs/ubifs/super.c
@@ -28,6 +28,8 @@
 #include <linux/writeback.h>
 #else
 
+#include <common.h>
+#include <malloc.h>
 #include <linux/compat.h>
 #include <linux/stat.h>
 #include <linux/err.h>
diff --git a/include/common.h b/include/common.h
index c12f402..c48e5bc 100644
--- a/include/common.h
+++ b/include/common.h
@@ -1060,15 +1060,6 @@ int cpu_release(int nr, int argc, char * const argv[]);
 #define DEFINE_CACHE_ALIGN_BUFFER(type, name, size)			\
 	DEFINE_ALIGN_BUFFER(type, name, size, ARCH_DMA_MINALIGN)
 
-#ifndef __ASSEMBLY__
-#include <malloc.h>
-
-static inline void *malloc_cache_aligned(size_t size)
-{
-	return memalign(ARCH_DMA_MINALIGN, ALIGN(size, ARCH_DMA_MINALIGN));
-}
-#endif
-
 /*
  * check_member() - Check the offset of a structure member
  *
diff --git a/include/malloc.h b/include/malloc.h
index f4da9e6..1d6327e 100644
--- a/include/malloc.h
+++ b/include/malloc.h
@@ -953,6 +953,18 @@ extern ulong mem_malloc_start;
 extern ulong mem_malloc_end;
 extern ulong mem_malloc_brk;
 
+/*
+ * ARCH_DMA_MINALIGN is defined by including common.h which should be the
+ * first include in a U-Boot C file. Protect this declaration for imported
+ * files which don't follow this convention, to avoid compile errors.
+ */
+#ifdef ARCH_DMA_MINALIGN
+static inline void *malloc_cache_aligned(size_t size)
+{
+	return memalign(ARCH_DMA_MINALIGN, ALIGN(size, ARCH_DMA_MINALIGN));
+}
+#endif
+
 void mem_malloc_init(ulong start, ulong size);
 
 #ifdef __cplusplus
diff --git a/lib/zlib/zutil.c b/lib/zlib/zutil.c
index 173a81d..227343e 100644
--- a/lib/zlib/zutil.c
+++ b/lib/zlib/zutil.c
@@ -43,7 +43,9 @@ void z_error (m)
  */
 #ifndef MY_ZCALLOC /* Any system without a special alloc function */
 
-#ifndef __UBOOT__
+#ifdef __UBOOT__
+#include <malloc.h>
+#else
 #ifndef STDC
 extern voidp    malloc OF((uInt size));
 extern voidp    calloc OF((uInt items, uInt size));
-- 
2.5.0.457.gab17608



More information about the U-Boot mailing list