[NET] Cleanup: DIV_ROUND_UP
[safe/jmp/linux-2.6] / net / key / af_key.c
index d302dda..17b2a69 100644 (file)
@@ -352,16 +352,14 @@ static int verify_address_len(void *p)
 
        switch (addr->sa_family) {
        case AF_INET:
-               len  = sizeof(*sp) + sizeof(*sin) + (sizeof(uint64_t) - 1);
-               len /= sizeof(uint64_t);
+               len = DIV_ROUND_UP(sizeof(*sp) + sizeof(*sin), sizeof(uint64_t));
                if (sp->sadb_address_len != len ||
                    sp->sadb_address_prefixlen > 32)
                        return -EINVAL;
                break;
 #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
        case AF_INET6:
-               len  = sizeof(*sp) + sizeof(*sin6) + (sizeof(uint64_t) - 1);
-               len /= sizeof(uint64_t);
+               len = DIV_ROUND_UP(sizeof(*sp) + sizeof(*sin6), sizeof(uint64_t));
                if (sp->sadb_address_len != len ||
                    sp->sadb_address_prefixlen > 128)
                        return -EINVAL;
@@ -386,14 +384,9 @@ static int verify_address_len(void *p)
 
 static inline int pfkey_sec_ctx_len(struct sadb_x_sec_ctx *sec_ctx)
 {
-       int len = 0;
-
-       len += sizeof(struct sadb_x_sec_ctx);
-       len += sec_ctx->sadb_x_ctx_len;
-       len += sizeof(uint64_t) - 1;
-       len /= sizeof(uint64_t);
-
-       return len;
+       return DIV_ROUND_UP(sizeof(struct sadb_x_sec_ctx) +
+                           sec_ctx->sadb_x_ctx_len,
+                           sizeof(uint64_t));
 }
 
 static inline int verify_sec_ctx_len(void *p)
@@ -1206,6 +1199,9 @@ static struct xfrm_state * pfkey_msg2xfrm_state(struct sadb_msg *hdr,
                x->sel.prefixlen_s = addr->sadb_address_prefixlen;
        }
 
+       if (!x->sel.family)
+               x->sel.family = x->props.family;
+
        if (ext_hdrs[SADB_X_EXT_NAT_T_TYPE-1]) {
                struct sadb_x_nat_t_type* n_type;
                struct xfrm_encap_tmpl *natt;
@@ -1682,6 +1678,7 @@ static int pfkey_flush(struct sock *sk, struct sk_buff *skb, struct sadb_msg *hd
        unsigned proto;
        struct km_event c;
        struct xfrm_audit audit_info;
+       int err;
 
        proto = pfkey_satype2proto(hdr->sadb_msg_satype);
        if (proto == 0)
@@ -1689,7 +1686,9 @@ static int pfkey_flush(struct sock *sk, struct sk_buff *skb, struct sadb_msg *hd
 
        audit_info.loginuid = audit_get_loginuid(current->audit_context);
        audit_info.secid = 0;
-       xfrm_state_flush(proto, &audit_info);
+       err = xfrm_state_flush(proto, &audit_info);
+       if (err)
+               return err;
        c.data.proto = proto;
        c.seq = hdr->sadb_msg_seq;
        c.pid = hdr->sadb_msg_pid;
@@ -2537,7 +2536,7 @@ static int pfkey_migrate(struct sock *sk, struct sk_buff *skb,
        sel.proto = pfkey_proto_to_xfrm(sa->sadb_address_proto);
        sel.sport = ((struct sockaddr_in *)(sa + 1))->sin_port;
        if (sel.sport)
-               sel.sport_mask = ~0;
+               sel.sport_mask = htons(0xffff);
 
        /* set destination address info of selector */
        sa = ext_hdrs[SADB_EXT_ADDRESS_DST - 1],
@@ -2546,7 +2545,7 @@ static int pfkey_migrate(struct sock *sk, struct sk_buff *skb,
        sel.proto = pfkey_proto_to_xfrm(sa->sadb_address_proto);
        sel.dport = ((struct sockaddr_in *)(sa + 1))->sin_port;
        if (sel.dport)
-               sel.dport_mask = ~0;
+               sel.dport_mask = htons(0xffff);
 
        rq = (struct sadb_x_ipsecrequest *)(pol + 1);
 
@@ -2683,10 +2682,13 @@ static int pfkey_spdflush(struct sock *sk, struct sk_buff *skb, struct sadb_msg
 {
        struct km_event c;
        struct xfrm_audit audit_info;
+       int err;
 
        audit_info.loginuid = audit_get_loginuid(current->audit_context);
        audit_info.secid = 0;
-       xfrm_policy_flush(XFRM_POLICY_TYPE_MAIN, &audit_info);
+       err = xfrm_policy_flush(XFRM_POLICY_TYPE_MAIN, &audit_info);
+       if (err)
+               return err;
        c.data.type = XFRM_POLICY_TYPE_MAIN;
        c.event = XFRM_MSG_FLUSHPOLICY;
        c.pid = hdr->sadb_msg_pid;