[NET] sem2mutex: net/
[linux-2.6.git] / net / ipv6 / ipcomp6.c
index 85bfbc6..3c7b324 100644 (file)
 #include <linux/rtnetlink.h>
 #include <net/icmp.h>
 #include <net/ipv6.h>
+#include <net/protocol.h>
 #include <linux/ipv6.h>
 #include <linux/icmpv6.h>
+#include <linux/mutex.h>
 
 struct ipcomp6_tfms {
        struct list_head list;
@@ -56,7 +58,7 @@ struct ipcomp6_tfms {
        int users;
 };
 
-static DECLARE_MUTEX(ipcomp6_resource_sem);
+static DEFINE_MUTEX(ipcomp6_resource_mutex);
 static void **ipcomp6_scratches;
 static int ipcomp6_scratch_users;
 static LIST_HEAD(ipcomp6_tfms_list);
@@ -130,8 +132,7 @@ static int ipcomp6_input(struct xfrm_state *x, struct xfrm_decap_state *decap, s
 out_put_cpu:
        put_cpu();
 out:
-       if (tmp_hdr)
-               kfree(tmp_hdr);
+       kfree(tmp_hdr);
        if (err)
                goto error_out;
        return nexthdr;
@@ -212,8 +213,7 @@ static void ipcomp6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
        if (!x)
                return;
 
-       printk(KERN_DEBUG "pmtu discovery on SA IPCOMP/%08x/"
-                       "%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x\n",
+       printk(KERN_DEBUG "pmtu discovery on SA IPCOMP/%08x/" NIP6_FMT "\n",
                        spi, NIP6(iph->daddr));
        xfrm_state_put(x);
 }
@@ -287,8 +287,8 @@ static void ipcomp6_free_scratches(void)
 
        for_each_cpu(i) {
                void *scratch = *per_cpu_ptr(scratches, i);
-               if (scratch)
-                       vfree(scratch);
+
+               vfree(scratch);
        }
 
        free_percpu(scratches);
@@ -406,9 +406,9 @@ static void ipcomp6_destroy(struct xfrm_state *x)
        if (!ipcd)
                return;
        xfrm_state_delete_tunnel(x);
-       down(&ipcomp6_resource_sem);
+       mutex_lock(&ipcomp6_resource_mutex);
        ipcomp6_free_data(ipcd);
-       up(&ipcomp6_resource_sem);
+       mutex_unlock(&ipcomp6_resource_mutex);
        kfree(ipcd);
 
        xfrm6_tunnel_free_spi((xfrm_address_t *)&x->props.saddr);
@@ -437,14 +437,14 @@ static int ipcomp6_init_state(struct xfrm_state *x)
        if (x->props.mode)
                x->props.header_len += sizeof(struct ipv6hdr);
        
-       down(&ipcomp6_resource_sem);
+       mutex_lock(&ipcomp6_resource_mutex);
        if (!ipcomp6_alloc_scratches())
                goto error;
 
        ipcd->tfms = ipcomp6_alloc_tfms(x->calg->alg_name);
        if (!ipcd->tfms)
                goto error;
-       up(&ipcomp6_resource_sem);
+       mutex_unlock(&ipcomp6_resource_mutex);
 
        if (x->props.mode) {
                err = ipcomp6_tunnel_attach(x);
@@ -460,10 +460,10 @@ static int ipcomp6_init_state(struct xfrm_state *x)
 out:
        return err;
 error_tunnel:
-       down(&ipcomp6_resource_sem);
+       mutex_lock(&ipcomp6_resource_mutex);
 error:
        ipcomp6_free_data(ipcd);
-       up(&ipcomp6_resource_sem);
+       mutex_unlock(&ipcomp6_resource_mutex);
        kfree(ipcd);
 
        goto out;