Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933273AbdC2Vi5 (ORCPT ); Wed, 29 Mar 2017 17:38:57 -0400 Received: from terminus.zytor.com ([65.50.211.136]:39031 "EHLO mail.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933079AbdC2Vit (ORCPT ); Wed, 29 Mar 2017 17:38:49 -0400 Subject: Re: [PATCH] kernel.h: add IS_PTR_ALIGNED() macro To: Masahiro Yamada , Andrew Morton References: <1490782930-30429-1-git-send-email-yamada.masahiro@socionext.com> Cc: =?UTF-8?Q?Niklas_S=c3=b6derlund?= , Jessica Yu , Johannes Berg , Petr Mladek , Larry Finger , linux-kernel@vger.kernel.org, Gustavo Padovan , Rasmus Villemoes , Peter Zijlstra , Luis de Bethencourt , Josh Triplett From: "H. Peter Anvin" Message-ID: Date: Wed, 29 Mar 2017 14:24:47 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: <1490782930-30429-1-git-send-email-yamada.masahiro@socionext.com> Content-Type: multipart/mixed; boundary="------------F6DF90D7043FC5C04CF94155" Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3811 Lines: 78 This is a multi-part message in MIME format. --------------F6DF90D7043FC5C04CF94155 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit 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 --------------F6DF90D7043FC5C04CF94155 Content-Type: text/plain; charset=UTF-8; name="uinttype.c" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="uinttype.c" LyoKICogVGhlc2UgYXJlIHR5cGVzOiBjb3JyZXNwb25kaW5nIHRvIHRoZSBzbWFsbGVzdCB1 bnNpZ25lZC9zaWduZWQKICogaW50ZWdlciB0eXBlIG5vIHNtYWxsZXIgdGhhbiBpbnQgb3Ig bG9uZywgcmVzcGVjdGl2ZWx5LCBjYXBhYmxlIG9mCiAqIGhvbGRpbmcgdGhlIGFyZ3VtZW50 ICh3aGljaCBjYW4gYmUgYW55dGhpbmcgdGhhdCBjYW4gYmUgdmFsaWRseQogKiBwYXNzZWQg dG8gc2l6ZW9mKCkuKQogKgogKiBJZiB0aGUgc2l6ZSBpcyB0b28gbGFyZ2UgZXZlbiBmb3Ig YSBsb25nIGxvbmcsIHRoZXkgcmV0dXJuIGFuCiAqIHVubmFtZWQgc3RydWN0dXJlIHR5cGUg d2l0aCB0aGUgcmlnaHQgc2l6ZW9mKCksIHdoaWNoIGlmIHVzZWQgZm9yIGEKICogY2FzdCB3 aWxsIGdlbmVyYXRlIHRoZSBlcnJvciBtZXNzYWdlOgogKgogKiBlcnJvcjogY29udmVyc2lv biB0byBub24tc2NhbGFyIHR5cGUgcmVxdWVzdGVkCiAqLwojZGVmaW5lIF9fdWludHR5cGUo eCkJCQkJCQkJXAogI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