net: introduce helper macro for_each_cmsghdr
Subsystems (10)
PATCH v2 1/1 net: introduce helper macro for_each_cmsghdr
Introduce helper macro for_each_cmsghdr as a wrapper of the enumerating cmsghdr from msghdr, just cleanup.
---
v2: use the lower-case macro name as Joe suggested.
--- .../networking/timestamping/timestamping.c | 4 +--- .../networking/timestamping/txtimestamp.c | 4 +--- crypto/af_alg.c | 2 +- include/linux/socket.h | 4 ++++ net/core/scm.c | 3 +-- net/dccp/proto.c | 5 ++--- net/ipv4/ip_sockglue.c | 2 +- net/ipv6/datagram.c | 2 +- net/iucv/af_iucv.c | 4 +--- net/rds/send.c | 4 ++-- net/rxrpc/ar-output.c | 2 +- net/sctp/socket.c | 3 +-- 12 files changed, 17 insertions(+), 22 deletions(-)
Documentation/networking/timestamping/timestamping.c +1 -3
@@ -169,9 +169,7 @@ static void printpacket(struct msghdr *msg, int res, res,inet_ntoa (from_addr->sin_addr), msg->msg_controllen); -for (cmsg =CMSG_FIRSTHDR (msg); - cmsg; - cmsg =CMSG_NXTHDR (msg, cmsg)) { +for_each_cmsghdr (cmsg, msg) {printf (" cmsg len %zu: " , cmsg->cmsg_len);switch (cmsg->cmsg_level) {case SOL_SOCKET :
Documentation/networking/timestamping/txtimestamp.c +1 -3
@@ -149,9 +149,7 @@ static void __recv_errmsg_cmsg(struct msghdr *msg, int payload_len)struct scm_timestamping *tss =NULL ;struct cmsghdr *cm; -for (cm =CMSG_FIRSTHDR (msg); - cm && cm->cmsg_len; - cm =CMSG_NXTHDR (msg, cm)) { +for_each_cmsghdr (cmsg, msg) {if (cm->cmsg_level ==SOL_SOCKET && cm->cmsg_type ==SCM_TIMESTAMPING ) { tss = (void *)CMSG_DATA (cm);
crypto/af_alg.c +1 -1
@@ -399,7 +399,7 @@ int af_alg_cmsg_send(struct msghdr *msg, struct af_alg_control *con) {struct cmsghdr *cmsg; -for (cmsg =CMSG_FIRSTHDR (msg); cmsg; cmsg =CMSG_NXTHDR (msg, cmsg)) { +for_each_cmsghdr (cmsg, msg) {if (!CMSG_OK (msg, cmsg))return -EINVAL ;if (cmsg->cmsg_level !=SOL_ALG )
include/linux/socket.h +4 -0
@@ -94,6 +94,10 @@ struct cmsghdr { (cmsg)->cmsg_len <= (unsigned long) \ ((mhdr)->msg_controllen - \ ((char *)(cmsg) - (char *)(mhdr)->msg_control))) +#define for_each_cmsg_hdr (cmsg, msg) \ + for (cmsg = CMSG_FIRSTHDR(msg); \ + cmsg; \ + cmsg = CMSG_NXTHDR(msg, cmsg))/* * Get the next cmsg header
net/core/scm.c +1 -2
@@ -129,8 +129,7 @@ int __scm_send(struct socket *sock, struct msghdr *msg, struct scm_cookie *p)struct cmsghdr *cmsg;int err; -for (cmsg =CMSG_FIRSTHDR (msg); cmsg; cmsg =CMSG_NXTHDR (msg, cmsg)) - { +for_each_cmsghdr (cmsg, msg) { err = -EINVAL ;/* Verify that cmsg_len is at least sizeof(struct cmsghdr) */
net/dccp/proto.c +2 -3
@@ -703,7 +703,7 @@ EXPORT_SYMBOL_GPL(compat_dccp_getsockopt);static int dccp_msghdr_parse (struct msghdr *msg,struct sk_buff *skb) { -struct cmsghdr *cmsg =CMSG_FIRSTHDR (msg); +struct cmsghdr *cmsg;/* * Assign an (opaque) qpolicy priority value to skb->priority.
@@ -717,8 +717,7 @@ static int dccp_msghdr_parse(struct msghdr *msg, struct sk_buff *skb)*/ skb->priority =0 ; -for (; cmsg !=NULL ; cmsg =CMSG_NXTHDR (msg, cmsg)) { - +for_each_cmsghdr (cmsg, msg) {if (!CMSG_OK (msg, cmsg))return -EINVAL ;
net/ipv4/ip_sockglue.c +1 -1
@@ -192,7 +192,7 @@ int ip_cmsg_send(struct net *net, struct msghdr *msg, struct ipcm_cookie *ipc,int err, val;struct cmsghdr *cmsg; -for (cmsg =CMSG_FIRSTHDR (msg); cmsg; cmsg =CMSG_NXTHDR (msg, cmsg)) { +for_each_cmsghdr (cmsg, msg) {if (!CMSG_OK (msg, cmsg))return -EINVAL ;#if IS_ENABLED (CONFIG_IPV6 )
net/ipv6/datagram.c +1 -1
@@ -640,7 +640,7 @@ int ip6_datagram_send_ctl(struct net *net, struct sock *sk,int len;int err =0 ; -for (cmsg =CMSG_FIRSTHDR (msg); cmsg; cmsg =CMSG_NXTHDR (msg, cmsg)) { +for_each_cmsghdr (cmsg, msg) {int addr_type;if (!CMSG_OK (msg, cmsg)) {
net/iucv/af_iucv.c +1 -3
@@ -1070,9 +1070,7 @@ static int iucv_sock_sendmsg(struct kiocb *iocb, struct socket *sock, txmsg.class =0 ;/* iterate over control messages */ -for (cmsg =CMSG_FIRSTHDR (msg); cmsg; - cmsg =CMSG_NXTHDR (msg, cmsg)) { - +for_each_cmsghdr (cmsg, msg) {if (!CMSG_OK (msg, cmsg)) { err = -EINVAL ; goto out;
net/rds/send.c +2 -2
@@ -826,7 +826,7 @@ static int rds_rm_size(struct msghdr *msg, int data_len)int cmsg_groups =0 ;int retval; -for (cmsg =CMSG_FIRSTHDR (msg); cmsg; cmsg =CMSG_NXTHDR (msg, cmsg)) { +for_each_cmsghdr (cmsg, msg) {if (!CMSG_OK (msg, cmsg))return -EINVAL ;
@@ -878,7 +878,7 @@ static int rds_cmsg_send(struct rds_sock *rs, struct rds_message *rm,struct cmsghdr *cmsg;int ret =0 ; -for (cmsg =CMSG_FIRSTHDR (msg); cmsg; cmsg =CMSG_NXTHDR (msg, cmsg)) { +for_each_cmsghdr (cmsg, msg) {if (!CMSG_OK (msg, cmsg))return -EINVAL ;
net/rxrpc/ar-output.c +1 -1
@@ -45,7 +45,7 @@ static int rxrpc_sendmsg_cmsg(struct rxrpc_sock *rx, struct msghdr *msg,if (msg->msg_controllen ==0 )return -EINVAL ; -for (cmsg =CMSG_FIRSTHDR (msg); cmsg; cmsg =CMSG_NXTHDR (msg, cmsg)) { +for_each_cmsghdr (cmsg, msg) {if (!CMSG_OK (msg, cmsg))return -EINVAL ;
net/sctp/socket.c +1 -2
@@ -6592,8 +6592,7 @@ static int sctp_msghdr_parse(const struct msghdr *msg, sctp_cmsgs_t *cmsgs)struct cmsghdr *cmsg;struct msghdr *my_msg = (struct msghdr *)msg; -for (cmsg =CMSG_FIRSTHDR (msg); cmsg !=NULL ; - cmsg =CMSG_NXTHDR (my_msg, cmsg)) { +for_each_cmsghdr (cmsg, my_msg) {if (!CMSG_OK (my_msg, cmsg))return -EINVAL ;
Signature · 1 line
1.7.7
There's a mistake in this patch, please ignore it. Sorry for the noise.
Regards,
Gu
Quoted 207 lines · Gu Zheng
Introduce helper macro
for_each_cmsghdras a wrapper of the enumerating cmsghdr from msghdr, just cleanup.Signed-off-by Gu Zheng <[email protected]>---
v2: use the lower-case macro name as Joe suggested.--- .../networking/timestamping/timestamping.c | 4 +--- .../networking/timestamping/txtimestamp.c | 4 +--- crypto/af_alg.c | 2 +- include/linux/socket.h | 4 ++++ net/core/scm.c | 3 +-- net/dccp/proto.c | 5 ++--- net/ipv4/ip_sockglue.c | 2 +- net/ipv6/datagram.c | 2 +- net/iucv/af_iucv.c | 4 +--- net/rds/send.c | 4 ++-- net/rxrpc/ar-output.c | 2 +- net/sctp/socket.c | 3 +-- 12 files changed, 17 insertions(+), 22 deletions(-)Documentation/networking/timestamping/timestamping.c +1
-3@@ -169,9 +169,7 @@ static void printpacket(struct msghdr *msg, int res, res,inet_ntoa (from_addr->sin_addr), msg->msg_controllen); -for (cmsg =CMSG_FIRSTHDR (msg); - cmsg; - cmsg =CMSG_NXTHDR (msg, cmsg)) { +for_each_cmsghdr (cmsg, msg) {printf (" cmsg len %zu: " , cmsg->cmsg_len);switch (cmsg->cmsg_level) {case SOL_SOCKET :Documentation/networking/timestamping/txtimestamp.c +1
-3@@ -149,9 +149,7 @@ static void __recv_errmsg_cmsg(struct msghdr *msg, int payload_len)struct scm_timestamping *tss =NULL ;struct cmsghdr *cm; -for (cm =CMSG_FIRSTHDR (msg); - cm && cm->cmsg_len; - cm =CMSG_NXTHDR (msg, cm)) { +for_each_cmsghdr (cmsg, msg) {if (cm->cmsg_level ==SOL_SOCKET && cm->cmsg_type ==SCM_TIMESTAMPING ) { tss = (void *)CMSG_DATA (cm);crypto/af_alg.c +1
-1@@ -399,7 +399,7 @@ int af_alg_cmsg_send(struct msghdr *msg, struct af_alg_control *con) {struct cmsghdr *cmsg; -for (cmsg =CMSG_FIRSTHDR (msg); cmsg; cmsg =CMSG_NXTHDR (msg, cmsg)) { +for_each_cmsghdr (cmsg, msg) {if (!CMSG_OK (msg, cmsg))return -EINVAL ;if (cmsg->cmsg_level !=SOL_ALG )include/linux/socket.h +4
-0@@ -94,6 +94,10 @@ struct cmsghdr { (cmsg)->cmsg_len <= (unsigned long) \ ((mhdr)->msg_controllen - \ ((char *)(cmsg) - (char *)(mhdr)->msg_control))) +#define for_each_cmsg_hdr (cmsg, msg) \ + for (cmsg = CMSG_FIRSTHDR(msg); \ + cmsg; \ + cmsg = CMSG_NXTHDR(msg, cmsg))/* * Get the next cmsg header net/core/scm.c +1
-2@@ -129,8 +129,7 @@ int __scm_send(struct socket *sock, struct msghdr *msg, struct scm_cookie *p)struct cmsghdr *cmsg;int err; -for (cmsg =CMSG_FIRSTHDR (msg); cmsg; cmsg =CMSG_NXTHDR (msg, cmsg)) - { +for_each_cmsghdr (cmsg, msg) { err = -EINVAL ;/* Verify that cmsg_len is at least sizeof(struct cmsghdr) */ net/dccp/proto.c +2
-3@@ -703,7 +703,7 @@ EXPORT_SYMBOL_GPL(compat_dccp_getsockopt);static int dccp_msghdr_parse (struct msghdr *msg,struct sk_buff *skb) { -struct cmsghdr *cmsg =CMSG_FIRSTHDR (msg); +struct cmsghdr *cmsg;/* * Assign an (opaque) qpolicy priority value to skb->priority. @@ -717,8 +717,7 @@ static int dccp_msghdr_parse(struct msghdr *msg, struct sk_buff *skb)*/ skb->priority =0 ; -for (; cmsg !=NULL ; cmsg =CMSG_NXTHDR (msg, cmsg)) { - +for_each_cmsghdr (cmsg, msg) {if (!CMSG_OK (msg, cmsg))return -EINVAL ;net/ipv4/ip_sockglue.c +1
-1@@ -192,7 +192,7 @@ int ip_cmsg_send(struct net *net, struct msghdr *msg, struct ipcm_cookie *ipc,int err, val;struct cmsghdr *cmsg; -for (cmsg =CMSG_FIRSTHDR (msg); cmsg; cmsg =CMSG_NXTHDR (msg, cmsg)) { +for_each_cmsghdr (cmsg, msg) {if (!CMSG_OK (msg, cmsg))return -EINVAL ;#if IS_ENABLED (CONFIG_IPV6 )net/ipv6/datagram.c +1
-1@@ -640,7 +640,7 @@ int ip6_datagram_send_ctl(struct net *net, struct sock *sk,int len;int err =0 ; -for (cmsg =CMSG_FIRSTHDR (msg); cmsg; cmsg =CMSG_NXTHDR (msg, cmsg)) { +for_each_cmsghdr (cmsg, msg) {int addr_type;if (!CMSG_OK (msg, cmsg)) {net/iucv/af_iucv.c +1
-3@@ -1070,9 +1070,7 @@ static int iucv_sock_sendmsg(struct kiocb *iocb, struct socket *sock, txmsg.class =0 ;/* iterate over control messages */ -for (cmsg =CMSG_FIRSTHDR (msg); cmsg; - cmsg =CMSG_NXTHDR (msg, cmsg)) { - +for_each_cmsghdr (cmsg, msg) {if (!CMSG_OK (msg, cmsg)) { err = -EINVAL ; goto out;net/rds/send.c +2
-2@@ -826,7 +826,7 @@ static int rds_rm_size(struct msghdr *msg, int data_len)int cmsg_groups =0 ;int retval; -for (cmsg =CMSG_FIRSTHDR (msg); cmsg; cmsg =CMSG_NXTHDR (msg, cmsg)) { +for_each_cmsghdr (cmsg, msg) {if (!CMSG_OK (msg, cmsg))return -EINVAL ;@@ -878,7 +878,7 @@ static int rds_cmsg_send(struct rds_sock *rs, struct rds_message *rm,struct cmsghdr *cmsg;int ret =0 ; -for (cmsg =CMSG_FIRSTHDR (msg); cmsg; cmsg =CMSG_NXTHDR (msg, cmsg)) { +for_each_cmsghdr (cmsg, msg) {if (!CMSG_OK (msg, cmsg))return -EINVAL ;net/rxrpc/ar-output.c +1
-1@@ -45,7 +45,7 @@ static int rxrpc_sendmsg_cmsg(struct rxrpc_sock *rx, struct msghdr *msg,if (msg->msg_controllen ==0 )return -EINVAL ; -for (cmsg =CMSG_FIRSTHDR (msg); cmsg; cmsg =CMSG_NXTHDR (msg, cmsg)) { +for_each_cmsghdr (cmsg, msg) {if (!CMSG_OK (msg, cmsg))return -EINVAL ;net/sctp/socket.c +1
-2@@ -6592,8 +6592,7 @@ static int sctp_msghdr_parse(const struct msghdr *msg, sctp_cmsgs_t *cmsgs)struct cmsghdr *cmsg;struct msghdr *my_msg = (struct msghdr *)msg; -for (cmsg =CMSG_FIRSTHDR (msg); cmsg !=NULL ; - cmsg =CMSG_NXTHDR (my_msg, cmsg)) { +for_each_cmsghdr (cmsg, my_msg) {if (!CMSG_OK (my_msg, cmsg))return -EINVAL ;
Quoted 2 lines · Gu Zheng
Introduce helper macro
for_each_cmsghdras a wrapper of the enumerating cmsghdr from msghdr, just cleanup.
Does this even compile?
So which is it?
for_each_cmsghdr
or
for_each_cmsg_hdr?
The .h #defines for_each_cmsg_hdr
but all the uses are for_each_cmsghdr
Documentation/networking/timestamping/timestamping.c
Quoted 1 line
Documentation/networking/timestamping/timestamping.c +0
-0
[]
crypto/af_alg.c
Quoted 12 lines
Documentation/networking/timestamping/timestamping.c +1
-3@@ -169,9 +169,7 @@ static void printpacket(struct msghdr *msg, int res, res,inet_ntoa (from_addr->sin_addr), msg->msg_controllen); -for (cmsg =CMSG_FIRSTHDR (msg); - cmsg; - cmsg =CMSG_NXTHDR (msg, cmsg)) { +for_each_cmsghdr (cmsg, msg) {printf (" cmsg len %zu: " , cmsg->cmsg_len);switch (cmsg->cmsg_level) {case SOL_SOCKET :crypto/af_alg.c +0
-0
[]
include/linux/socket.h
Quoted 10 lines
crypto/af_alg.c +1
-1@@ -399,7 +399,7 @@ int af_alg_cmsg_send(struct msghdr *msg, struct af_alg_control *con) {struct cmsghdr *cmsg; -for (cmsg =CMSG_FIRSTHDR (msg); cmsg; cmsg =CMSG_NXTHDR (msg, cmsg)) { +for_each_cmsghdr (cmsg, msg) {if (!CMSG_OK (msg, cmsg))return -EINVAL ;if (cmsg->cmsg_level !=SOL_ALG )include/linux/socket.h +0
-0
[]
Quoted 8 lines
include/linux/socket.h +4
-0@@ -94,6 +94,10 @@ struct cmsghdr { (cmsg)->cmsg_len <= (unsigned long) \ ((mhdr)->msg_controllen - \ ((char *)(cmsg) - (char *)(mhdr)->msg_control))) +#define for_each_cmsg_hdr (cmsg, msg) \ + for (cmsg = CMSG_FIRSTHDR(msg); \ + cmsg; \ + cmsg = CMSG_NXTHDR(msg, cmsg))
Hi Joe,
Quoted 6 lines · Joe Perches
Quoted 2 lines · Gu Zheng
Introduce helper macro
for_each_cmsghdras a wrapper of the enumerating cmsghdr from msghdr, just cleanup.Does this even compile?
Quoted 8 lines
So which is it?
for_each_cmsghdr
or
for_each_cmsg_hdr?The .h #defines
for_each_cmsg_hdr
but all the uses arefor_each_cmsghdr
Thanks for your quick feedback.
There seems some problems with my send-patch script, it sent out the patch before the test completed.
Thanks,
Gu
Quoted 40 lines
Documentation/networking/timestamping/timestamping.c
Quoted 2 lines
Documentation/networking/timestamping/timestamping.c +0
-0[]
crypto/af_alg.c
Quoted 12 lines
Documentation/networking/timestamping/timestamping.c +1
-3@@ -169,9 +169,7 @@ static void printpacket(struct msghdr *msg, int res, res,inet_ntoa (from_addr->sin_addr), msg->msg_controllen); -for (cmsg =CMSG_FIRSTHDR (msg); - cmsg; - cmsg =CMSG_NXTHDR (msg, cmsg)) { +for_each_cmsghdr (cmsg, msg) {printf (" cmsg len %zu: " , cmsg->cmsg_len);switch (cmsg->cmsg_level) {case SOL_SOCKET :crypto/af_alg.c +0
-0[]
include/linux/socket.h
Quoted 10 lines
crypto/af_alg.c +1
-1@@ -399,7 +399,7 @@ int af_alg_cmsg_send(struct msghdr *msg, struct af_alg_control *con) {struct cmsghdr *cmsg; -for (cmsg =CMSG_FIRSTHDR (msg); cmsg; cmsg =CMSG_NXTHDR (msg, cmsg)) { +for_each_cmsghdr (cmsg, msg) {if (!CMSG_OK (msg, cmsg))return -EINVAL ;if (cmsg->cmsg_level !=SOL_ALG )include/linux/socket.h +0
-0[]
include/linux/socket.h struct cmsghdr { · line 100
Quoted 8 lines
include/linux/socket.h +4
-0@@ -94,6 +94,10 @@ struct cmsghdr { (cmsg)->cmsg_len <= (unsigned long) \ ((mhdr)->msg_controllen - \ ((char *)(cmsg) - (char *)(mhdr)->msg_control))) +#define for_each_cmsg_hdr (cmsg, msg) \ + for (cmsg = CMSG_FIRSTHDR(msg); \ + cmsg; \ + cmsg = CMSG_NXTHDR(msg, cmsg)).