Commit f95b414e authored by Gu Zheng's avatar Gu Zheng Committed by David S. Miller

net: introduce helper macro for_each_cmsghdr

Introduce helper macro for_each_cmsghdr as a wrapper of the enumerating
cmsghdr from msghdr, just cleanup.
Signed-off-by: default avatarGu Zheng <guz.fnst@cn.fujitsu.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent dd0bcc0b
...@@ -399,7 +399,7 @@ int af_alg_cmsg_send(struct msghdr *msg, struct af_alg_control *con) ...@@ -399,7 +399,7 @@ int af_alg_cmsg_send(struct msghdr *msg, struct af_alg_control *con)
{ {
struct cmsghdr *cmsg; struct cmsghdr *cmsg;
for (cmsg = CMSG_FIRSTHDR(msg); cmsg; cmsg = CMSG_NXTHDR(msg, cmsg)) { for_each_cmsghdr(cmsg, msg) {
if (!CMSG_OK(msg, cmsg)) if (!CMSG_OK(msg, cmsg))
return -EINVAL; return -EINVAL;
if (cmsg->cmsg_level != SOL_ALG) if (cmsg->cmsg_level != SOL_ALG)
......
...@@ -103,6 +103,10 @@ struct cmsghdr { ...@@ -103,6 +103,10 @@ struct cmsghdr {
(cmsg)->cmsg_len <= (unsigned long) \ (cmsg)->cmsg_len <= (unsigned long) \
((mhdr)->msg_controllen - \ ((mhdr)->msg_controllen - \
((char *)(cmsg) - (char *)(mhdr)->msg_control))) ((char *)(cmsg) - (char *)(mhdr)->msg_control)))
#define for_each_cmsghdr(cmsg, msg) \
for (cmsg = CMSG_FIRSTHDR(msg); \
cmsg; \
cmsg = CMSG_NXTHDR(msg, cmsg))
/* /*
* Get the next cmsg header * Get the next cmsg header
......
...@@ -129,8 +129,7 @@ int __scm_send(struct socket *sock, struct msghdr *msg, struct scm_cookie *p) ...@@ -129,8 +129,7 @@ int __scm_send(struct socket *sock, struct msghdr *msg, struct scm_cookie *p)
struct cmsghdr *cmsg; struct cmsghdr *cmsg;
int err; int err;
for (cmsg = CMSG_FIRSTHDR(msg); cmsg; cmsg = CMSG_NXTHDR(msg, cmsg)) for_each_cmsghdr(cmsg, msg) {
{
err = -EINVAL; err = -EINVAL;
/* Verify that cmsg_len is at least sizeof(struct cmsghdr) */ /* Verify that cmsg_len is at least sizeof(struct cmsghdr) */
......
...@@ -703,7 +703,7 @@ EXPORT_SYMBOL_GPL(compat_dccp_getsockopt); ...@@ -703,7 +703,7 @@ EXPORT_SYMBOL_GPL(compat_dccp_getsockopt);
static int dccp_msghdr_parse(struct msghdr *msg, struct sk_buff *skb) 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. * 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) ...@@ -717,8 +717,7 @@ static int dccp_msghdr_parse(struct msghdr *msg, struct sk_buff *skb)
*/ */
skb->priority = 0; skb->priority = 0;
for (; cmsg != NULL; cmsg = CMSG_NXTHDR(msg, cmsg)) { for_each_cmsghdr(cmsg, msg) {
if (!CMSG_OK(msg, cmsg)) if (!CMSG_OK(msg, cmsg))
return -EINVAL; return -EINVAL;
......
...@@ -192,7 +192,7 @@ int ip_cmsg_send(struct net *net, struct msghdr *msg, struct ipcm_cookie *ipc, ...@@ -192,7 +192,7 @@ int ip_cmsg_send(struct net *net, struct msghdr *msg, struct ipcm_cookie *ipc,
int err, val; int err, val;
struct cmsghdr *cmsg; struct cmsghdr *cmsg;
for (cmsg = CMSG_FIRSTHDR(msg); cmsg; cmsg = CMSG_NXTHDR(msg, cmsg)) { for_each_cmsghdr(cmsg, msg) {
if (!CMSG_OK(msg, cmsg)) if (!CMSG_OK(msg, cmsg))
return -EINVAL; return -EINVAL;
#if IS_ENABLED(CONFIG_IPV6) #if IS_ENABLED(CONFIG_IPV6)
......
...@@ -657,7 +657,7 @@ int ip6_datagram_send_ctl(struct net *net, struct sock *sk, ...@@ -657,7 +657,7 @@ int ip6_datagram_send_ctl(struct net *net, struct sock *sk,
int len; int len;
int err = 0; int err = 0;
for (cmsg = CMSG_FIRSTHDR(msg); cmsg; cmsg = CMSG_NXTHDR(msg, cmsg)) { for_each_cmsghdr(cmsg, msg) {
int addr_type; int addr_type;
if (!CMSG_OK(msg, cmsg)) { if (!CMSG_OK(msg, cmsg)) {
......
...@@ -1070,9 +1070,7 @@ static int iucv_sock_sendmsg(struct kiocb *iocb, struct socket *sock, ...@@ -1070,9 +1070,7 @@ static int iucv_sock_sendmsg(struct kiocb *iocb, struct socket *sock,
txmsg.class = 0; txmsg.class = 0;
/* iterate over control messages */ /* iterate over control messages */
for (cmsg = CMSG_FIRSTHDR(msg); cmsg; for_each_cmsghdr(cmsg, msg) {
cmsg = CMSG_NXTHDR(msg, cmsg)) {
if (!CMSG_OK(msg, cmsg)) { if (!CMSG_OK(msg, cmsg)) {
err = -EINVAL; err = -EINVAL;
goto out; goto out;
......
...@@ -826,7 +826,7 @@ static int rds_rm_size(struct msghdr *msg, int data_len) ...@@ -826,7 +826,7 @@ static int rds_rm_size(struct msghdr *msg, int data_len)
int cmsg_groups = 0; int cmsg_groups = 0;
int retval; int retval;
for (cmsg = CMSG_FIRSTHDR(msg); cmsg; cmsg = CMSG_NXTHDR(msg, cmsg)) { for_each_cmsghdr(cmsg, msg) {
if (!CMSG_OK(msg, cmsg)) if (!CMSG_OK(msg, cmsg))
return -EINVAL; return -EINVAL;
...@@ -878,7 +878,7 @@ static int rds_cmsg_send(struct rds_sock *rs, struct rds_message *rm, ...@@ -878,7 +878,7 @@ static int rds_cmsg_send(struct rds_sock *rs, struct rds_message *rm,
struct cmsghdr *cmsg; struct cmsghdr *cmsg;
int ret = 0; int ret = 0;
for (cmsg = CMSG_FIRSTHDR(msg); cmsg; cmsg = CMSG_NXTHDR(msg, cmsg)) { for_each_cmsghdr(cmsg, msg) {
if (!CMSG_OK(msg, cmsg)) if (!CMSG_OK(msg, cmsg))
return -EINVAL; return -EINVAL;
......
...@@ -45,7 +45,7 @@ static int rxrpc_sendmsg_cmsg(struct rxrpc_sock *rx, struct msghdr *msg, ...@@ -45,7 +45,7 @@ static int rxrpc_sendmsg_cmsg(struct rxrpc_sock *rx, struct msghdr *msg,
if (msg->msg_controllen == 0) if (msg->msg_controllen == 0)
return -EINVAL; return -EINVAL;
for (cmsg = CMSG_FIRSTHDR(msg); cmsg; cmsg = CMSG_NXTHDR(msg, cmsg)) { for_each_cmsghdr(cmsg, msg) {
if (!CMSG_OK(msg, cmsg)) if (!CMSG_OK(msg, cmsg))
return -EINVAL; return -EINVAL;
......
...@@ -6592,8 +6592,7 @@ static int sctp_msghdr_parse(const struct msghdr *msg, sctp_cmsgs_t *cmsgs) ...@@ -6592,8 +6592,7 @@ static int sctp_msghdr_parse(const struct msghdr *msg, sctp_cmsgs_t *cmsgs)
struct cmsghdr *cmsg; struct cmsghdr *cmsg;
struct msghdr *my_msg = (struct msghdr *)msg; struct msghdr *my_msg = (struct msghdr *)msg;
for (cmsg = CMSG_FIRSTHDR(msg); cmsg != NULL; for_each_cmsghdr(cmsg, my_msg) {
cmsg = CMSG_NXTHDR(my_msg, cmsg)) {
if (!CMSG_OK(my_msg, cmsg)) if (!CMSG_OK(my_msg, cmsg))
return -EINVAL; return -EINVAL;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment