mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] kernel.h: add IS_PTR_ALIGNED() macro
@ 2017-03-29 10:22 Masahiro Yamada
  2017-03-29 21:24 ` H. Peter Anvin
  2017-03-29 21:36 ` Andrew Morton
  0 siblings, 2 replies; 6+ messages in thread
From: Masahiro Yamada @ 2017-03-29 10:22 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Masahiro Yamada, Niklas Söderlund, Jessica Yu,
	Johannes Berg, Petr Mladek, Larry Finger, linux-kernel,
	Gustavo Padovan, Rasmus Villemoes, Peter Zijlstra,
	Luis de Bethencourt, Josh Triplett

We often check if a pointer has a specific alignment.  Because the
'&' (bitwise AND) operator cannot take a pointer for the operand,
so we need a cast like, IS_ALIGNED((unsigned long)p, a).

IS_PTR_ALIGNED will be useful as a shorthand.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
---

 include/linux/kernel.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index e5edd55..a810e4b 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -50,6 +50,7 @@
 #define __ALIGN_MASK(x, mask)	__ALIGN_KERNEL_MASK((x), (mask))
 #define PTR_ALIGN(p, a)		((typeof(p))ALIGN((unsigned long)(p), (a)))
 #define IS_ALIGNED(x, a)		(((x) & ((typeof(x))(a) - 1)) == 0)
+#define IS_PTR_ALIGNED(p, a)		(IS_ALIGNED((unsigned long)p, a))
 
 /* generic data direction definitions */
 #define READ			0
-- 
2.7.4

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2017-03-30 15:23 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-29 10:22 [PATCH] kernel.h: add IS_PTR_ALIGNED() macro Masahiro Yamada
2017-03-29 21:24 ` H. Peter Anvin
2017-03-30  1:57   ` Masahiro Yamada
2017-03-30  3:29     ` H. Peter Anvin
2017-03-30 15:22       ` Masahiro Yamada
2017-03-29 21:36 ` Andrew Morton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®