[NET]: cleanup extra semicolons
[powerpc.git] / net / xfrm / xfrm_user.c
index 2567453..f91521d 100644 (file)
@@ -71,7 +71,7 @@ static int verify_one_alg(struct rtattr **xfrma, enum xfrm_attr_type_t type)
 
        default:
                return -EINVAL;
-       };
+       }
 
        algp->alg_name[CRYPTO_MAX_ALG_NAME - 1] = '\0';
        return 0;
@@ -152,7 +152,7 @@ static int verify_newsa_info(struct xfrm_usersa_info *p,
 
        default:
                goto out;
-       };
+       }
 
        err = -EINVAL;
        switch (p->id.proto) {
@@ -192,7 +192,7 @@ static int verify_newsa_info(struct xfrm_usersa_info *p,
 
        default:
                goto out;
-       };
+       }
 
        if ((err = verify_one_alg(xfrma, XFRMA_ALG_AUTH)))
                goto out;
@@ -217,7 +217,7 @@ static int verify_newsa_info(struct xfrm_usersa_info *p,
 
        default:
                goto out;
-       };
+       }
 
        err = 0;
 
@@ -272,9 +272,8 @@ static int attach_encap_tmpl(struct xfrm_encap_tmpl **encapp, struct rtattr *u_a
 }
 
 
-static inline int xfrm_user_sec_ctx_size(struct xfrm_policy *xp)
+static inline int xfrm_user_sec_ctx_size(struct xfrm_sec_ctx *xfrm_ctx)
 {
-       struct xfrm_sec_ctx *xfrm_ctx = xp->security;
        int len = 0;
 
        if (xfrm_ctx) {
@@ -530,9 +529,6 @@ static int xfrm_del_sa(struct sk_buff *skb, struct nlmsghdr *nlh,
 
        err = xfrm_state_delete(x);
 
-       xfrm_audit_log(NETLINK_CB(skb).loginuid, NETLINK_CB(skb).sid,
-                      AUDIT_MAC_IPSEC_DELSA, err ? 0 : 1, NULL, x);
-
        if (err < 0)
                goto out;
 
@@ -542,6 +538,8 @@ static int xfrm_del_sa(struct sk_buff *skb, struct nlmsghdr *nlh,
        km_state_notify(x, &c);
 
 out:
+       xfrm_audit_log(NETLINK_CB(skb).loginuid, NETLINK_CB(skb).sid,
+                      AUDIT_MAC_IPSEC_DELSA, err ? 0 : 1, NULL, x);
        xfrm_state_put(x);
        return err;
 }
@@ -578,7 +576,7 @@ static int dump_one_state(struct xfrm_state *x, int count, void *ptr)
        struct sk_buff *skb = sp->out_skb;
        struct xfrm_usersa_info *p;
        struct nlmsghdr *nlh;
-       unsigned char *b = skb->tail;
+       unsigned char *b = skb_tail_pointer(skb);
 
        if (sp->this_idx < sp->start_idx)
                goto out;
@@ -623,14 +621,14 @@ static int dump_one_state(struct xfrm_state *x, int count, void *ptr)
        if (x->lastused)
                RTA_PUT(skb, XFRMA_LASTUSED, sizeof(x->lastused), &x->lastused);
 
-       nlh->nlmsg_len = skb->tail - b;
+       nlh->nlmsg_len = skb_tail_pointer(skb) - b;
 out:
        sp->this_idx++;
        return 0;
 
 nlmsg_failure:
 rtattr_failure:
-       skb_trim(skb, b - skb->data);
+       nlmsg_trim(skb, b);
        return -1;
 }
 
@@ -713,7 +711,7 @@ static int verify_userspi_info(struct xfrm_userspi_info *p)
 
        default:
                return -EINVAL;
-       };
+       }
 
        if (p->min > p->max)
                return -EINVAL;
@@ -791,7 +789,7 @@ static int verify_policy_dir(u8 dir)
 
        default:
                return -EINVAL;
-       };
+       }
 
        return 0;
 }
@@ -807,7 +805,7 @@ static int verify_policy_type(u8 type)
 
        default:
                return -EINVAL;
-       };
+       }
 
        return 0;
 }
@@ -823,7 +821,7 @@ static int verify_newpolicy_info(struct xfrm_userpolicy_info *p)
 
        default:
                return -EINVAL;
-       };
+       }
 
        switch (p->action) {
        case XFRM_POLICY_ALLOW:
@@ -832,7 +830,7 @@ static int verify_newpolicy_info(struct xfrm_userpolicy_info *p)
 
        default:
                return -EINVAL;
-       };
+       }
 
        switch (p->sel.family) {
        case AF_INET:
@@ -847,7 +845,7 @@ static int verify_newpolicy_info(struct xfrm_userpolicy_info *p)
 
        default:
                return -EINVAL;
-       };
+       }
 
        return verify_policy_dir(p->dir);
 }
@@ -914,7 +912,7 @@ static int validate_tmpl(int nr, struct xfrm_user_tmpl *ut, u16 family)
 #endif
                default:
                        return -EINVAL;
-               };
+               }
        }
 
        return 0;
@@ -1159,7 +1157,7 @@ static int dump_one_policy(struct xfrm_policy *xp, int dir, int count, void *ptr
        struct sk_buff *in_skb = sp->in_skb;
        struct sk_buff *skb = sp->out_skb;
        struct nlmsghdr *nlh;
-       unsigned char *b = skb->tail;
+       unsigned char *b = skb_tail_pointer(skb);
 
        if (sp->this_idx < sp->start_idx)
                goto out;
@@ -1178,13 +1176,13 @@ static int dump_one_policy(struct xfrm_policy *xp, int dir, int count, void *ptr
        if (copy_to_user_policy_type(xp->type, skb) < 0)
                goto nlmsg_failure;
 
-       nlh->nlmsg_len = skb->tail - b;
+       nlh->nlmsg_len = skb_tail_pointer(skb) - b;
 out:
        sp->this_idx++;
        return 0;
 
 nlmsg_failure:
-       skb_trim(skb, b - skb->data);
+       nlmsg_trim(skb, b);
        return -1;
 }
 
@@ -1254,7 +1252,7 @@ static int xfrm_get_policy(struct sk_buff *skb, struct nlmsghdr *nlh,
                return err;
 
        if (p->index)
-               xp = xfrm_policy_byid(type, p->dir, p->index, delete);
+               xp = xfrm_policy_byid(type, p->dir, p->index, delete, &err);
        else {
                struct rtattr *rt = xfrma[XFRMA_SEC_CTX-1];
                struct xfrm_policy tmp;
@@ -1270,7 +1268,8 @@ static int xfrm_get_policy(struct sk_buff *skb, struct nlmsghdr *nlh,
                        if ((err = security_xfrm_policy_alloc(&tmp, uctx)))
                                return err;
                }
-               xp = xfrm_policy_bysel_ctx(type, p->dir, &p->sel, tmp.security, delete);
+               xp = xfrm_policy_bysel_ctx(type, p->dir, &p->sel, tmp.security,
+                                          delete, &err);
                security_xfrm_policy_free(&tmp);
        }
        if (xp == NULL)
@@ -1288,8 +1287,6 @@ static int xfrm_get_policy(struct sk_buff *skb, struct nlmsghdr *nlh,
                                              MSG_DONTWAIT);
                }
        } else {
-               err = security_xfrm_policy_delete(xp);
-
                xfrm_audit_log(NETLINK_CB(skb).loginuid, NETLINK_CB(skb).sid,
                               AUDIT_MAC_IPSEC_DELSPD, err ? 0 : 1, xp, NULL);
 
@@ -1303,9 +1300,8 @@ static int xfrm_get_policy(struct sk_buff *skb, struct nlmsghdr *nlh,
                km_policy_notify(xp, p->dir, &c);
        }
 
-       xfrm_pol_put(xp);
-
 out:
+       xfrm_pol_put(xp);
        return err;
 }
 
@@ -1334,7 +1330,7 @@ static int build_aevent(struct sk_buff *skb, struct xfrm_state *x, struct km_eve
        struct xfrm_aevent_id *id;
        struct nlmsghdr *nlh;
        struct xfrm_lifetime_cur ltime;
-       unsigned char *b = skb->tail;
+       unsigned char *b = skb_tail_pointer(skb);
 
        nlh = NLMSG_PUT(skb, c->pid, c->seq, XFRM_MSG_NEWAE, sizeof(*id));
        id = NLMSG_DATA(nlh);
@@ -1366,12 +1362,12 @@ static int build_aevent(struct sk_buff *skb, struct xfrm_state *x, struct km_eve
                RTA_PUT(skb,XFRMA_ETIMER_THRESH,sizeof(u32),&etimer);
        }
 
-       nlh->nlmsg_len = skb->tail - b;
+       nlh->nlmsg_len = skb_tail_pointer(skb) - b;
        return skb->len;
 
 rtattr_failure:
 nlmsg_failure:
-       skb_trim(skb, b - skb->data);
+       nlmsg_trim(skb, b);
        return -1;
 }
 
@@ -1401,7 +1397,7 @@ static int xfrm_get_ae(struct sk_buff *skb, struct nlmsghdr *nlh,
 
        x = xfrm_state_lookup(&id->daddr, id->spi, id->proto, id->family);
        if (x == NULL) {
-               kfree(r_skb);
+               kfree_skb(r_skb);
                return -ESRCH;
        }
 
@@ -1502,7 +1498,7 @@ static int xfrm_add_pol_expire(struct sk_buff *skb, struct nlmsghdr *nlh,
                return err;
 
        if (p->index)
-               xp = xfrm_policy_byid(type, p->dir, p->index, 0);
+               xp = xfrm_policy_byid(type, p->dir, p->index, 0, &err);
        else {
                struct rtattr *rt = xfrma[XFRMA_SEC_CTX-1];
                struct xfrm_policy tmp;
@@ -1518,13 +1514,14 @@ static int xfrm_add_pol_expire(struct sk_buff *skb, struct nlmsghdr *nlh,
                        if ((err = security_xfrm_policy_alloc(&tmp, uctx)))
                                return err;
                }
-               xp = xfrm_policy_bysel_ctx(type, p->dir, &p->sel, tmp.security, 0);
+               xp = xfrm_policy_bysel_ctx(type, p->dir, &p->sel, tmp.security,
+                                          0, &err);
                security_xfrm_policy_free(&tmp);
        }
 
        if (xp == NULL)
-               return err;
-                                                                                       read_lock(&xp->lock);
+               return -ENOENT;
+       read_lock(&xp->lock);
        if (xp->dead) {
                read_unlock(&xp->lock);
                goto out;
@@ -1557,14 +1554,13 @@ static int xfrm_add_sa_expire(struct sk_buff *skb, struct nlmsghdr *nlh,
        struct xfrm_usersa_info *p = &ue->state;
 
        x = xfrm_state_lookup(&p->id.daddr, p->id.spi, p->id.proto, p->family);
-               err = -ENOENT;
 
+       err = -ENOENT;
        if (x == NULL)
                return err;
 
-       err = -EINVAL;
-
        spin_lock_bh(&x->lock);
+       err = -EINVAL;
        if (x->km.state != XFRM_STATE_VALID)
                goto out;
        km_state_expired(x, ue->hard, current->pid);
@@ -1574,6 +1570,7 @@ static int xfrm_add_sa_expire(struct sk_buff *skb, struct nlmsghdr *nlh,
                xfrm_audit_log(NETLINK_CB(skb).loginuid, NETLINK_CB(skb).sid,
                               AUDIT_MAC_IPSEC_DELSA, 1, NULL, x);
        }
+       err = 0;
 out:
        spin_unlock_bh(&x->lock);
        xfrm_state_put(x);
@@ -1747,7 +1744,7 @@ static int build_migrate(struct sk_buff *skb, struct xfrm_migrate *m,
        struct xfrm_migrate *mp;
        struct xfrm_userpolicy_id *pol_id;
        struct nlmsghdr *nlh;
-       unsigned char *b = skb->tail;
+       unsigned char *b = skb_tail_pointer(skb);
        int i;
 
        nlh = NLMSG_PUT(skb, 0, 0, XFRM_MSG_MIGRATE, sizeof(*pol_id));
@@ -1767,10 +1764,10 @@ static int build_migrate(struct sk_buff *skb, struct xfrm_migrate *m,
                        goto nlmsg_failure;
        }
 
-       nlh->nlmsg_len = skb->tail - b;
+       nlh->nlmsg_len = skb_tail_pointer(skb) - b;
        return skb->len;
 nlmsg_failure:
-       skb_trim(skb, b - skb->data);
+       nlmsg_trim(skb, b);
        return -1;
 }
 
@@ -1855,53 +1852,36 @@ static struct xfrm_link {
        [XFRM_MSG_MIGRATE     - XFRM_MSG_BASE] = { .doit = xfrm_do_migrate    },
 };
 
-static int xfrm_user_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh, int *errp)
+static int xfrm_user_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
 {
        struct rtattr *xfrma[XFRMA_MAX];
        struct xfrm_link *link;
        int type, min_len;
 
-       if (!(nlh->nlmsg_flags & NLM_F_REQUEST))
-               return 0;
-
        type = nlh->nlmsg_type;
-
-       /* A control message: ignore them */
-       if (type < XFRM_MSG_BASE)
-               return 0;
-
-       /* Unknown message: reply with EINVAL */
        if (type > XFRM_MSG_MAX)
-               goto err_einval;
+               return -EINVAL;
 
        type -= XFRM_MSG_BASE;
        link = &xfrm_dispatch[type];
 
        /* All operations require privileges, even GET */
-       if (security_netlink_recv(skb, CAP_NET_ADMIN)) {
-               *errp = -EPERM;
-               return -1;
-       }
+       if (security_netlink_recv(skb, CAP_NET_ADMIN))
+               return -EPERM;
 
        if ((type == (XFRM_MSG_GETSA - XFRM_MSG_BASE) ||
             type == (XFRM_MSG_GETPOLICY - XFRM_MSG_BASE)) &&
            (nlh->nlmsg_flags & NLM_F_DUMP)) {
                if (link->dump == NULL)
-                       goto err_einval;
-
-               if ((*errp = netlink_dump_start(xfrm_nl, skb, nlh,
-                                               link->dump, NULL)) != 0) {
-                       return -1;
-               }
+                       return -EINVAL;
 
-               netlink_queue_skip(nlh, skb);
-               return -1;
+               return netlink_dump_start(xfrm_nl, skb, nlh, link->dump, NULL);
        }
 
        memset(xfrma, 0, sizeof(xfrma));
 
        if (nlh->nlmsg_len < (min_len = xfrm_msg_min[type]))
-               goto err_einval;
+               return -EINVAL;
 
        if (nlh->nlmsg_len > min_len) {
                int attrlen = nlh->nlmsg_len - NLMSG_ALIGN(min_len);
@@ -1911,7 +1891,7 @@ static int xfrm_user_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh, int *err
                        unsigned short flavor = attr->rta_type;
                        if (flavor) {
                                if (flavor > XFRMA_MAX)
-                                       goto err_einval;
+                                       return -EINVAL;
                                xfrma[flavor - 1] = attr;
                        }
                        attr = RTA_NEXT(attr, attrlen);
@@ -1919,14 +1899,9 @@ static int xfrm_user_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh, int *err
        }
 
        if (link->doit == NULL)
-               goto err_einval;
-       *errp = link->doit(skb, nlh, xfrma);
-
-       return *errp;
+               return -EINVAL;
 
-err_einval:
-       *errp = -EINVAL;
-       return -1;
+       return link->doit(skb, nlh, xfrma);
 }
 
 static void xfrm_netlink_rcv(struct sock *sk, int len)
@@ -1945,7 +1920,7 @@ static int build_expire(struct sk_buff *skb, struct xfrm_state *x, struct km_eve
 {
        struct xfrm_user_expire *ue;
        struct nlmsghdr *nlh;
-       unsigned char *b = skb->tail;
+       unsigned char *b = skb_tail_pointer(skb);
 
        nlh = NLMSG_PUT(skb, c->pid, 0, XFRM_MSG_EXPIRE,
                        sizeof(*ue));
@@ -1955,11 +1930,11 @@ static int build_expire(struct sk_buff *skb, struct xfrm_state *x, struct km_eve
        copy_to_user_state(x, &ue->state);
        ue->hard = (c->data.hard != 0) ? 1 : 0;
 
-       nlh->nlmsg_len = skb->tail - b;
+       nlh->nlmsg_len = skb_tail_pointer(skb) - b;
        return skb->len;
 
 nlmsg_failure:
-       skb_trim(skb, b - skb->data);
+       nlmsg_trim(skb, b);
        return -1;
 }
 
@@ -2002,7 +1977,7 @@ static int xfrm_notify_sa_flush(struct km_event *c)
        struct xfrm_usersa_flush *p;
        struct nlmsghdr *nlh;
        struct sk_buff *skb;
-       unsigned char *b;
+       sk_buff_data_t b;
        int len = NLMSG_LENGTH(sizeof(struct xfrm_usersa_flush));
 
        skb = alloc_skb(len, GFP_ATOMIC);
@@ -2027,7 +2002,7 @@ nlmsg_failure:
        return -1;
 }
 
-static int inline xfrm_sa_len(struct xfrm_state *x)
+static inline int xfrm_sa_len(struct xfrm_state *x)
 {
        int l = 0;
        if (x->aalg)
@@ -2048,7 +2023,7 @@ static int xfrm_notify_sa(struct xfrm_state *x, struct km_event *c)
        struct xfrm_usersa_id *id;
        struct nlmsghdr *nlh;
        struct sk_buff *skb;
-       unsigned char *b;
+       sk_buff_data_t b;
        int len = xfrm_sa_len(x);
        int headlen;
 
@@ -2132,7 +2107,7 @@ static int build_acquire(struct sk_buff *skb, struct xfrm_state *x,
 {
        struct xfrm_user_acquire *ua;
        struct nlmsghdr *nlh;
-       unsigned char *b = skb->tail;
+       unsigned char *b = skb_tail_pointer(skb);
        __u32 seq = xfrm_get_acqseq();
 
        nlh = NLMSG_PUT(skb, 0, 0, XFRM_MSG_ACQUIRE,
@@ -2156,11 +2131,11 @@ static int build_acquire(struct sk_buff *skb, struct xfrm_state *x,
        if (copy_to_user_policy_type(xp->type, skb) < 0)
                goto nlmsg_failure;
 
-       nlh->nlmsg_len = skb->tail - b;
+       nlh->nlmsg_len = skb_tail_pointer(skb) - b;
        return skb->len;
 
 nlmsg_failure:
-       skb_trim(skb, b - skb->data);
+       nlmsg_trim(skb, b);
        return -1;
 }
 
@@ -2172,7 +2147,7 @@ static int xfrm_send_acquire(struct xfrm_state *x, struct xfrm_tmpl *xt,
 
        len = RTA_SPACE(sizeof(struct xfrm_user_tmpl) * xp->xfrm_nr);
        len += NLMSG_SPACE(sizeof(struct xfrm_user_acquire));
-       len += RTA_SPACE(xfrm_user_sec_ctx_size(xp));
+       len += RTA_SPACE(xfrm_user_sec_ctx_size(x->security));
 #ifdef CONFIG_XFRM_SUB_POLICY
        len += RTA_SPACE(sizeof(struct xfrm_userpolicy_type));
 #endif
@@ -2252,7 +2227,7 @@ static int build_polexpire(struct sk_buff *skb, struct xfrm_policy *xp,
        struct xfrm_user_polexpire *upe;
        struct nlmsghdr *nlh;
        int hard = c->data.hard;
-       unsigned char *b = skb->tail;
+       unsigned char *b = skb_tail_pointer(skb);
 
        nlh = NLMSG_PUT(skb, c->pid, 0, XFRM_MSG_POLEXPIRE, sizeof(*upe));
        upe = NLMSG_DATA(nlh);
@@ -2267,11 +2242,11 @@ static int build_polexpire(struct sk_buff *skb, struct xfrm_policy *xp,
                goto nlmsg_failure;
        upe->hard = !!hard;
 
-       nlh->nlmsg_len = skb->tail - b;
+       nlh->nlmsg_len = skb_tail_pointer(skb) - b;
        return skb->len;
 
 nlmsg_failure:
-       skb_trim(skb, b - skb->data);
+       nlmsg_trim(skb, b);
        return -1;
 }
 
@@ -2282,7 +2257,7 @@ static int xfrm_exp_policy_notify(struct xfrm_policy *xp, int dir, struct km_eve
 
        len = RTA_SPACE(sizeof(struct xfrm_user_tmpl) * xp->xfrm_nr);
        len += NLMSG_SPACE(sizeof(struct xfrm_user_polexpire));
-       len += RTA_SPACE(xfrm_user_sec_ctx_size(xp));
+       len += RTA_SPACE(xfrm_user_sec_ctx_size(xp->security));
 #ifdef CONFIG_XFRM_SUB_POLICY
        len += RTA_SPACE(sizeof(struct xfrm_userpolicy_type));
 #endif
@@ -2303,7 +2278,7 @@ static int xfrm_notify_policy(struct xfrm_policy *xp, int dir, struct km_event *
        struct xfrm_userpolicy_id *id;
        struct nlmsghdr *nlh;
        struct sk_buff *skb;
-       unsigned char *b;
+       sk_buff_data_t b;
        int len = RTA_SPACE(sizeof(struct xfrm_user_tmpl) * xp->xfrm_nr);
        int headlen;
 
@@ -2360,7 +2335,7 @@ static int xfrm_notify_policy_flush(struct km_event *c)
 {
        struct nlmsghdr *nlh;
        struct sk_buff *skb;
-       unsigned char *b;
+       sk_buff_data_t b;
        int len = 0;
 #ifdef CONFIG_XFRM_SUB_POLICY
        len += RTA_SPACE(sizeof(struct xfrm_userpolicy_type));
@@ -2413,7 +2388,7 @@ static int build_report(struct sk_buff *skb, u8 proto,
 {
        struct xfrm_user_report *ur;
        struct nlmsghdr *nlh;
-       unsigned char *b = skb->tail;
+       unsigned char *b = skb_tail_pointer(skb);
 
        nlh = NLMSG_PUT(skb, 0, 0, XFRM_MSG_REPORT, sizeof(*ur));
        ur = NLMSG_DATA(nlh);
@@ -2425,12 +2400,12 @@ static int build_report(struct sk_buff *skb, u8 proto,
        if (addr)
                RTA_PUT(skb, XFRMA_COADDR, sizeof(*addr), addr);
 
-       nlh->nlmsg_len = skb->tail - b;
+       nlh->nlmsg_len = skb_tail_pointer(skb) - b;
        return skb->len;
 
 nlmsg_failure:
 rtattr_failure:
-       skb_trim(skb, b - skb->data);
+       nlmsg_trim(skb, b);
        return -1;
 }
 
@@ -2469,7 +2444,7 @@ static int __init xfrm_user_init(void)
        printk(KERN_INFO "Initializing XFRM netlink socket\n");
 
        nlsk = netlink_kernel_create(NETLINK_XFRM, XFRMNLGRP_MAX,
-                                    xfrm_netlink_rcv, THIS_MODULE);
+                                    xfrm_netlink_rcv, NULL, THIS_MODULE);
        if (nlsk == NULL)
                return -ENOMEM;
        rcu_assign_pointer(xfrm_nl, nlsk);