Skip to contentSkip to conversation

Move malloc_cache_aligned() to malloc.h

PATCH New Simon Glass 3 participants 4 messages Aug 29, 2015 – Sep 2, 2015 UBI file system (UBIFS)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Move malloc_cache_aligned() to malloc.h

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.

---

 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(-)
fs/ubifs/super.c +2 -0
index 0bf52db..74edff1 100644
@@ -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>
include/common.h +0 -9
index c12f402..c48e5bc 100644
@@ -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
  *
include/malloc.h +12 -0
index f4da9e6..1d6327e 100644
@@ -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
lib/zlib/zutil.c +3 -1
index 173a81d..227343e 100644
@@ -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));
Signature · 1 line
2.5.0.457.gab17608
#1 lore raw

PATCH 1/1 Move malloc_cache_aligned() to malloc.h

Quoted 4 lines · Simon Glass

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

Quoted 8 lines

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.

Hm, but we've been there before:

https://patchwork.ozlabs.org/patch/503291/

#2 lore raw

PATCH 1/1 Move malloc_cache_aligned() to malloc.h

Quoted 12 lines · Marcel Ziswiler
Quoted 11 lines · Simon Glass

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.

Quoted 5 lines
Quoted 1 line

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

Hm, but we've been there before:

https://patchwork.ozlabs.org/patch/503291/

Maybe all the cache alignment stuff could go in its own header?

-Scott

#3 lore raw

PATCH 1/1 Move malloc_cache_aligned() to malloc.h

Hi Scott,

Quoted 13 lines · Scott Wood
Quoted 12 lines · Marcel Ziswiler
Quoted 11 lines · Simon Glass

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.

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

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

Hm, but we've been there before:

https://patchwork.ozlabs.org/patch/503291/

Maybe all the cache alignment stuff could go in its own header?

Yes I like that idea, it seems like the best solution.

Regards,
Simon