Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tools: move alignment-related macros to new <linux/align.h>

Currently, tools have *ALIGN*() macros scattered across the unrelated
headers, as there are only 3 of them and they were added separately
each time on an as-needed basis.
Anyway, let's make it more consistent with the kernel headers and allow
using those macros outside of the mentioned headers. Create
<linux/align.h> inside the tools/ folder and include it where needed.

Signed-off-by: Yury Norov <yury.norov@gmail.com>
Signed-off-by: Alexander Lobakin <aleksander.lobakin@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Alexander Lobakin and committed by
David S. Miller
10a04ff0 4ca532d6

+14 -5
+12
tools/include/linux/align.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0-only */ 2 + 3 + #ifndef _TOOLS_LINUX_ALIGN_H 4 + #define _TOOLS_LINUX_ALIGN_H 5 + 6 + #include <uapi/linux/const.h> 7 + 8 + #define ALIGN(x, a) __ALIGN_KERNEL((x), (a)) 9 + #define ALIGN_DOWN(x, a) __ALIGN_KERNEL((x) - ((a) - 1), (a)) 10 + #define IS_ALIGNED(x, a) (((x) & ((typeof(x))(a) - 1)) == 0) 11 + 12 + #endif /* _TOOLS_LINUX_ALIGN_H */
+1 -1
tools/include/linux/bitmap.h
··· 3 3 #define _TOOLS_LINUX_BITMAP_H 4 4 5 5 #include <string.h> 6 + #include <linux/align.h> 6 7 #include <linux/bitops.h> 7 8 #include <linux/find.h> 8 9 #include <stdlib.h> ··· 127 126 #define BITMAP_MEM_ALIGNMENT (8 * sizeof(unsigned long)) 128 127 #endif 129 128 #define BITMAP_MEM_MASK (BITMAP_MEM_ALIGNMENT - 1) 130 - #define IS_ALIGNED(x, a) (((x) & ((typeof(x))(a) - 1)) == 0) 131 129 132 130 static inline bool bitmap_equal(const unsigned long *src1, 133 131 const unsigned long *src2, unsigned int nbits)
+1 -4
tools/include/linux/mm.h
··· 2 2 #ifndef _TOOLS_LINUX_MM_H 3 3 #define _TOOLS_LINUX_MM_H 4 4 5 + #include <linux/align.h> 5 6 #include <linux/mmzone.h> 6 - #include <uapi/linux/const.h> 7 7 8 8 #define PAGE_SHIFT 12 9 9 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT) 10 10 #define PAGE_MASK (~(PAGE_SIZE - 1)) 11 11 12 12 #define PHYS_ADDR_MAX (~(phys_addr_t)0) 13 - 14 - #define ALIGN(x, a) __ALIGN_KERNEL((x), (a)) 15 - #define ALIGN_DOWN(x, a) __ALIGN_KERNEL((x) - ((a) - 1), (a)) 16 13 17 14 #define PAGE_ALIGN(addr) ALIGN(addr, PAGE_SIZE) 18 15