Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1611792 > unrolled thread
| Started by | Masahiro Yamada <yamada.masahiro@socionext.com> |
|---|---|
| First post | 2017-03-29 12:30 +0200 |
| Last post | 2017-03-30 17:30 +0200 |
| Articles | 6 — 3 participants |
Back to article view | Back to linux.kernel
[PATCH] kernel.h: add IS_PTR_ALIGNED() macro Masahiro Yamada <yamada.masahiro@socionext.com> - 2017-03-29 12:30 +0200
Re: [PATCH] kernel.h: add IS_PTR_ALIGNED() macro Andrew Morton <akpm@linux-foundation.org> - 2017-03-29 23:40 +0200
Re: [PATCH] kernel.h: add IS_PTR_ALIGNED() macro "H. Peter Anvin" <hpa@zytor.com> - 2017-03-29 23:40 +0200
Re: [PATCH] kernel.h: add IS_PTR_ALIGNED() macro Masahiro Yamada <yamada.masahiro@socionext.com> - 2017-03-30 04:00 +0200
Re: [PATCH] kernel.h: add IS_PTR_ALIGNED() macro "H. Peter Anvin" <hpa@zytor.com> - 2017-03-30 05:50 +0200
Re: [PATCH] kernel.h: add IS_PTR_ALIGNED() macro Masahiro Yamada <yamada.masahiro@socionext.com> - 2017-03-30 17:30 +0200
| From | Masahiro Yamada <yamada.masahiro@socionext.com> |
|---|---|
| Date | 2017-03-29 12:30 +0200 |
| Subject | [PATCH] kernel.h: add IS_PTR_ALIGNED() macro |
| Message-ID | <tqj1w-5wl-21@gated-at.bofh.it> |
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
[toc] | [next] | [standalone]
| From | Andrew Morton <akpm@linux-foundation.org> |
|---|---|
| Date | 2017-03-29 23:40 +0200 |
| Message-ID | <tqttU-4o9-7@gated-at.bofh.it> |
| In reply to | #1611792 |
On Wed, 29 Mar 2017 19:22:10 +0900 Masahiro Yamada <yamada.masahiro@socionext.com> 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. > > ... > > --- 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 It would be nice to see some conversions which actually use this new macro.
[toc] | [prev] | [next] | [standalone]
| From | "H. Peter Anvin" <hpa@zytor.com> |
|---|---|
| Date | 2017-03-29 23:40 +0200 |
| Message-ID | <tqttU-4o9-19@gated-at.bofh.it> |
| In reply to | #1611792 |
[Multipart message — attachments visible in raw view] — view raw
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 <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)) > 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 <linux/kernel.h>. -hpa
[toc] | [prev] | [next] | [standalone]
| From | Masahiro Yamada <yamada.masahiro@socionext.com> |
|---|---|
| Date | 2017-03-30 04:00 +0200 |
| Message-ID | <tqxxv-7fz-3@gated-at.bofh.it> |
| In reply to | #1612385 |
Hi. 2017-03-30 6:24 GMT+09:00 H. Peter Anvin <hpa@zytor.com>: > 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 <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)) >> > > 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 <linux/kernel.h>. > > -hpa Could you care to send a patch? Perhaps, ALIGN and PTR_ALIGN can be merged as well? -- Best Regards Masahiro Yamada
[toc] | [prev] | [next] | [standalone]
| From | "H. Peter Anvin" <hpa@zytor.com> |
|---|---|
| Date | 2017-03-30 05:50 +0200 |
| Message-ID | <tqzfX-c7-7@gated-at.bofh.it> |
| In reply to | #1612493 |
On 03/29/17 18:57, Masahiro Yamada wrote: > > Could you care to send a patch? > > Perhaps, ALIGN and PTR_ALIGN can be merged as well? > Can't promise when I'd get around to it... -hpa
[toc] | [prev] | [next] | [standalone]
| From | Masahiro Yamada <yamada.masahiro@socionext.com> |
|---|---|
| Date | 2017-03-30 17:30 +0200 |
| Message-ID | <tqKbq-8iw-59@gated-at.bofh.it> |
| In reply to | #1612540 |
Hi. 2017-03-30 12:29 GMT+09:00 H. Peter Anvin <hpa@zytor.com>: > On 03/29/17 18:57, Masahiro Yamada wrote: >> >> Could you care to send a patch? >> >> Perhaps, ALIGN and PTR_ALIGN can be merged as well? >> > > Can't promise when I'd get around to it... > > -hpa OK. No need to rush now. Please take a look when you find some time. Andrew, Maybe, we should drop my patch for now, and take our time for better implementation? -- Best Regards Masahiro Yamada
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web