[PATCH 01/13] kexec: add _ALIGN* marcos for align operation

Zhang Yanfei zhangyanfei.yes at gmail.com
Wed Mar 13 13:19:13 EDT 2013


From: Zhang Yanfei <zhangyanfei at cn.fujitsu.com>

This patch imports Macros for align operation:
- _ALIGN_UP(addr, size): align addr up on a size boundary
- _ALIGN_DOWN(addr, size): align addr down on a size boundary
- _ALIGN(addr, size): align addr up on a size boundary

Signed-off-by: Zhang Yanfei <zhangyanfei at cn.fujitsu.com>
---
 kexec/kexec.h |   12 ++++++++++++
 1 files changed, 12 insertions(+), 0 deletions(-)

diff --git a/kexec/kexec.h b/kexec/kexec.h
index 94c62c1..916a24b 100644
--- a/kexec/kexec.h
+++ b/kexec/kexec.h
@@ -100,6 +100,18 @@ do { \
 	} \
 } while(0)
 
+#define _ALIGN_UP_MASK(addr, mask)   (((addr) + (mask)) & ~(mask))
+#define _ALIGN_DOWN_MASK(addr, mask) ((addr) & ~(mask))
+
+/* align addr on a size boundary - adjust address up/down if needed */
+#define _ALIGN_UP(addr, size)	     \
+	_ALIGN_UP_MASK(addr, (typeof(addr))(size) - 1)
+#define _ALIGN_DOWN(addr, size)	     \
+	_ALIGN_DOWN_MASK(addr, (typeof(addr))(size) - 1)
+
+/* align addr on a size boundary - adjust address up if needed */
+#define _ALIGN(addr, size)     _ALIGN_UP(addr, size)
+
 extern unsigned long long mem_min, mem_max;
 extern int kexec_debug;
 
-- 
1.7.1



More information about the kexec mailing list