[U-Boot] [PATCH] 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.
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));

On Sat, 2015-08-29 at 14:54 +0000, Simon Glass wrote:
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.
Hm, but we've been there before:

On Sun, 2015-08-30 at 20:28 +0000, Marcel Ziswiler wrote:
On Sat, 2015-08-29 at 14:54 +0000, Simon Glass wrote:
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.
Hm, but we've been there before:
Maybe all the cache alignment stuff could go in its own header?
-Scott

Hi Scott,
On 30 August 2015 at 14:30, Scott Wood scottwood@freescale.com wrote:
On Sun, 2015-08-30 at 20:28 +0000, Marcel Ziswiler wrote:
On Sat, 2015-08-29 at 14:54 +0000, Simon Glass wrote:
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.
Hm, but we've been there before:
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
participants (3)
-
Marcel Ziswiler
-
Scott Wood
-
Simon Glass