net: introduce helper macro for_each_cmsghdr
authorGu Zheng <guz.fnst@cn.fujitsu.com>
Thu, 11 Dec 2014 03:22:04 +0000 (11:22 +0800)
committerDavid S. Miller <davem@davemloft.net>
Thu, 11 Dec 2014 03:41:55 +0000 (22:41 -0500)
Introduce helper macro for_each_cmsghdr as a wrapper of the enumerating
cmsghdr from msghdr, just cleanup.

Signed-off-by: Gu Zheng <guz.fnst@cn.fujitsu.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
crypto/af_alg.c
include/linux/socket.h
net/core/scm.c
net/dccp/proto.c
net/ipv4/ip_sockglue.c
net/ipv6/datagram.c
net/iucv/af_iucv.c
net/rds/send.c
net/rxrpc/ar-output.c
net/sctp/socket.c

index 6a3ad80..bc21f52 100644 (file)
@@ -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)
index 048d6d6..6e49a14 100644 (file)
@@ -103,6 +103,10 @@ struct cmsghdr {
                             (cmsg)->cmsg_len <= (unsigned long) \
                             ((mhdr)->msg_controllen - \
                              ((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
index b442e7e..3b6899b 100644 (file)
@@ -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) */
index 19f0387..e171b78 100644 (file)
@@ -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;
 
index 640f26c..8a89c73 100644 (file)
@@ -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)
index 2464a00..100c589 100644 (file)
@@ -657,7 +657,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)) {
index 1cd3f81..2e9953b 100644 (file)
@@ -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;
index 40a5629..42f65d4 100644 (file)
@@ -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;
 
index 86e0f10..e1a9373 100644 (file)
@@ -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;
 
index c92f96c..2625ecc 100644 (file)
@@ -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;