public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot] [PATCH] Move malloc_cache_aligned() to malloc.h
@ 2015-08-29 14:54 Simon Glass
  2015-08-30 20:28 ` Marcel Ziswiler
  0 siblings, 1 reply; 4+ messages in thread
From: Simon Glass @ 2015-08-29 14:54 UTC (permalink / raw)
  To: u-boot

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@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

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-09-02  2:49 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-08-29 14:54 [U-Boot] [PATCH] Move malloc_cache_aligned() to malloc.h Simon Glass
2015-08-30 20:28 ` Marcel Ziswiler
2015-08-30 20:30   ` Scott Wood
2015-09-02  2:49     ` Simon Glass

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox