* [PATCH net-next] net: socket: use BIT_MASK for MSG_*
@ 2021-02-06 5:31 menglong8.dong
[not found] ` <CAHp75VfMYOz+qexix_TujGfUgFAtUXdbS=ekVdE_4cwRv5W8pw@mail.gmail.com>
0 siblings, 1 reply; 3+ messages in thread
From: menglong8.dong @ 2021-02-06 5:31 UTC (permalink / raw)
To: axboe; +Cc: davem, viro, herbert, dong.menglong, linux-kernel
From: Menglong Dong <dong.menglong@zte.com.cn>
The bit mask for MSG_* seems a little confused here. Replace it
with BIT_MASK to make it clear to understand.
Signed-off-by: Menglong Dong <dong.menglong@zte.com.cn>
---
include/linux/socket.h | 71 ++++++++++++++++++++++--------------------
1 file changed, 37 insertions(+), 34 deletions(-)
diff --git a/include/linux/socket.h b/include/linux/socket.h
index 385894b4a8bb..671d31c41582 100644
--- a/include/linux/socket.h
+++ b/include/linux/socket.h
@@ -283,42 +283,45 @@ struct ucred {
Added those for 1003.1g not all are supported yet
*/
-#define MSG_OOB 1
-#define MSG_PEEK 2
-#define MSG_DONTROUTE 4
-#define MSG_TRYHARD 4 /* Synonym for MSG_DONTROUTE for DECnet */
-#define MSG_CTRUNC 8
-#define MSG_PROBE 0x10 /* Do not send. Only probe path f.e. for MTU */
-#define MSG_TRUNC 0x20
-#define MSG_DONTWAIT 0x40 /* Nonblocking io */
-#define MSG_EOR 0x80 /* End of record */
-#define MSG_WAITALL 0x100 /* Wait for a full request */
-#define MSG_FIN 0x200
-#define MSG_SYN 0x400
-#define MSG_CONFIRM 0x800 /* Confirm path validity */
-#define MSG_RST 0x1000
-#define MSG_ERRQUEUE 0x2000 /* Fetch message from error queue */
-#define MSG_NOSIGNAL 0x4000 /* Do not generate SIGPIPE */
-#define MSG_MORE 0x8000 /* Sender will send more */
-#define MSG_WAITFORONE 0x10000 /* recvmmsg(): block until 1+ packets avail */
-#define MSG_SENDPAGE_NOPOLICY 0x10000 /* sendpage() internal : do no apply policy */
-#define MSG_SENDPAGE_NOTLAST 0x20000 /* sendpage() internal : not the last page */
-#define MSG_BATCH 0x40000 /* sendmmsg(): more messages coming */
-#define MSG_EOF MSG_FIN
-#define MSG_NO_SHARED_FRAGS 0x80000 /* sendpage() internal : page frags are not shared */
-#define MSG_SENDPAGE_DECRYPTED 0x100000 /* sendpage() internal : page may carry
- * plain text and require encryption
- */
-
-#define MSG_ZEROCOPY 0x4000000 /* Use user data in kernel path */
-#define MSG_FASTOPEN 0x20000000 /* Send data in TCP SYN */
-#define MSG_CMSG_CLOEXEC 0x40000000 /* Set close_on_exec for file
- descriptor received through
- SCM_RIGHTS */
+#define MSG_OOB BIT_MASK(0)
+#define MSG_PEEK BIT_MASK(1)
+#define MSG_DONTROUTE BIT_MASK(2)
+#define MSG_TRYHARD BIT_MASK(2) /* Synonym for MSG_DONTROUTE for DECnet */
+#define MSG_CTRUNC BIT_MASK(3)
+#define MSG_PROBE BIT_MASK(4) /* Do not send. Only probe path f.e. for MTU */
+#define MSG_TRUNC BIT_MASK(5)
+#define MSG_DONTWAIT BIT_MASK(6) /* Nonblocking io */
+#define MSG_EOR BIT_MASK(7) /* End of record */
+#define MSG_WAITALL BIT_MASK(8) /* Wait for a full request */
+#define MSG_FIN BIT_MASK(9)
+#define MSG_SYN BIT_MASK(10)
+#define MSG_CONFIRM BIT_MASK(11) /* Confirm path validity */
+#define MSG_RST BIT_MASK(12)
+#define MSG_ERRQUEUE BIT_MASK(13) /* Fetch message from error queue */
+#define MSG_NOSIGNAL BIT_MASK(14) /* Do not generate SIGPIPE */
+#define MSG_MORE BIT_MASK(15) /* Sender will send more */
+#define MSG_WAITFORONE BIT_MASK(16) /* recvmmsg(): block until 1+ packets avail */
+#define MSG_SENDPAGE_NOPOLICY BIT_MASK(16) /* sendpage() internal : do no apply policy */
+#define MSG_SENDPAGE_NOTLAST BIT_MASK(17) /* sendpage() internal : not the last page */
+#define MSG_BATCH BIT_MASK(18) /* sendmmsg(): more messages coming */
+#define MSG_EOF MSG_FIN
+#define MSG_NO_SHARED_FRAGS BIT_MASK(19) /* sendpage() internal : page frags
+ * are not shared
+ */
+#define MSG_SENDPAGE_DECRYPTED BIT_MASK(20) /* sendpage() internal : page may carry
+ * plain text and require encryption
+ */
+
+#define MSG_ZEROCOPY BIT_MASK(26) /* Use user data in kernel path */
+#define MSG_FASTOPEN BIT_MASK(29) /* Send data in TCP SYN */
+#define MSG_CMSG_CLOEXEC BIT_MASK(30) /* Set close_on_exec for file
+ * descriptor received through
+ * SCM_RIGHTS
+ */
#if defined(CONFIG_COMPAT)
-#define MSG_CMSG_COMPAT 0x80000000 /* This message needs 32 bit fixups */
+#define MSG_CMSG_COMPAT BIT_MASK(31) /* This message needs 32 bit fixups */
#else
-#define MSG_CMSG_COMPAT 0 /* We never have 32 bit fixups */
+#define MSG_CMSG_COMPAT 0 /* We never have 32 bit fixups */
#endif
--
2.30.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH net-next] net: socket: use BIT_MASK for MSG_*
[not found] ` <CAHp75VfMYOz+qexix_TujGfUgFAtUXdbS=ekVdE_4cwRv5W8pw@mail.gmail.com>
@ 2021-02-07 3:29 ` Menglong Dong
2021-02-07 11:50 ` Andy Shevchenko
0 siblings, 1 reply; 3+ messages in thread
From: Menglong Dong @ 2021-02-07 3:29 UTC (permalink / raw)
To: Andy Shevchenko; +Cc: axboe, davem, viro, herbert, dong.menglong, linux-kernel
Hello!
On Sat, Feb 6, 2021 at 4:20 PM Andy Shevchenko
<andy.shevchenko@gmail.com> wrote:
>
>
>
> On Saturday, February 6, 2021, <menglong8.dong@gmail.com> wrote:
>>
>> From: Menglong Dong <dong.menglong@zte.com.cn>
>>
>> The bit mask for MSG_* seems a little confused here. Replace it
>> with BIT_MASK to make it clear to understand.
>
>
> It makes it more confusing if you understand the difference between BIT_MASK() and BIT(). I think you have to use the latter. And note () when referring to the function or macro.
>
I replaced BIT_MASK() with BIT() in the patch of v2, and it looks much
more tidy.
I can't figure out the difference between BIT() and BIT_MASK(), seems
the latter one more safe... isn't it?
Thanks:)
Menglong Dong
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH net-next] net: socket: use BIT_MASK for MSG_*
2021-02-07 3:29 ` Menglong Dong
@ 2021-02-07 11:50 ` Andy Shevchenko
0 siblings, 0 replies; 3+ messages in thread
From: Andy Shevchenko @ 2021-02-07 11:50 UTC (permalink / raw)
To: Menglong Dong; +Cc: axboe, davem, viro, herbert, dong.menglong, linux-kernel
On Sun, Feb 7, 2021 at 5:29 AM Menglong Dong <menglong8.dong@gmail.com> wrote:
> On Sat, Feb 6, 2021 at 4:20 PM Andy Shevchenko
> <andy.shevchenko@gmail.com> wrote:
> > On Saturday, February 6, 2021, <menglong8.dong@gmail.com> wrote:
> > It makes it more confusing if you understand the difference between BIT_MASK() and BIT(). I think you have to use the latter. And note () when referring to the function or macro.
>
> I replaced BIT_MASK() with BIT() in the patch of v2, and it looks much
> more tidy.
> I can't figure out the difference between BIT() and BIT_MASK(), seems
> the latter one more safe... isn't it?
BIT_MASK() operates on top of (long) bitmaps when you already know the
address of the certain word you would like to change. When the
parameter is constant it will be helpful only in some (rare) cases,
where you define a (long) bit mask, which has a bit, like 65, set. For
most of the cases it's not needed. It's rare that hardware operates on
bitmaps longer than data bus width.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-02-07 11:55 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-06 5:31 [PATCH net-next] net: socket: use BIT_MASK for MSG_* menglong8.dong
[not found] ` <CAHp75VfMYOz+qexix_TujGfUgFAtUXdbS=ekVdE_4cwRv5W8pw@mail.gmail.com>
2021-02-07 3:29 ` Menglong Dong
2021-02-07 11:50 ` Andy Shevchenko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).