Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752862AbdC3B5f (ORCPT ); Wed, 29 Mar 2017 21:57:35 -0400 Received: from conssluserg-04.nifty.com ([210.131.2.83]:38459 "EHLO conssluserg-04.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751394AbdC3B5e (ORCPT ); Wed, 29 Mar 2017 21:57:34 -0400 DKIM-Filter: OpenDKIM Filter v2.10.3 conssluserg-04.nifty.com v2U1vSr5013975 X-Nifty-SrcIP: [209.85.213.179] MIME-Version: 1.0 In-Reply-To: References: <1490782930-30429-1-git-send-email-yamada.masahiro@socionext.com> From: Masahiro Yamada Date: Thu, 30 Mar 2017 10:57:27 +0900 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] kernel.h: add IS_PTR_ALIGNED() macro To: "H. Peter Anvin" Cc: Andrew Morton , =?UTF-8?Q?Niklas_S=C3=B6derlund?= , Jessica Yu , Johannes Berg , Petr Mladek , Larry Finger , Linux Kernel Mailing List , Gustavo Padovan , Rasmus Villemoes , Peter Zijlstra , Luis de Bethencourt , Josh Triplett Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1522 Lines: 48 Hi. 2017-03-30 6:24 GMT+09:00 H. Peter Anvin : > On 03/29/17 03:22, Masahiro Yamada wrote: >> 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 >> --- >> >> 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)) >> > > No need for two macros; make one work for both. > > You could move the __inttype() macro from arch/x86/include/asm/uaccess.h > into this file and replace typeof(x) with __inttype(x) in the above macro. > > Attached is a set of slightly improved (safer and a bit more > generalized) versions of the same macro that might be more appropriate > to include in . > > -hpa Could you care to send a patch? Perhaps, ALIGN and PTR_ALIGN can be merged as well? -- Best Regards Masahiro Yamada