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 <a.heider@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This commit is contained in:
parent
0fdd91d92b
commit
55f6869c33
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue