From 55f6869c33e62f6ba253e4fa6fcb9724288a0deb Mon Sep 17 00:00:00 2001 From: Andre Heider Date: Sat, 19 Oct 2013 14:20:48 +0200 Subject: common: add a macro to align an array on the stack The macro can be used for temporary stack buffers which need to meet a minimum alignment requirement. This will be used by bcm2835 mailbox users, where all buffers need to be aligned. Signed-off-by: Andre Heider Signed-off-by: Sascha Hauer --- include/common.h | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'include/common.h') diff --git a/include/common.h b/include/common.h index 0f0ba08c44..00f1642cd5 100644 --- a/include/common.h +++ b/include/common.h @@ -192,6 +192,17 @@ int run_shell(void); #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr)) #define ARRAY_AND_SIZE(x) (x), ARRAY_SIZE(x) +/* + * The STACK_ALIGN_ARRAY macro is used to allocate a buffer on the stack that + * meets a minimum alignment requirement. + * + * Note that the size parameter is the number of array elements to allocate, + * not the number of bytes. + */ +#define STACK_ALIGN_ARRAY(type, name, size, align) \ + char __##name[sizeof(type) * (size) + (align) - 1]; \ + type *name = (type *)ALIGN((uintptr_t)__##name, align) + /** * container_of - cast a member of a structure out to the containing structure * @ptr: the pointer to the member. -- cgit v1.2.3