cgroups: make cftype.unregister_event() void-returning
[safe/jmp/linux-2.6] / net / xfrm / xfrm_ipcomp.c
index b51e804..fc91ad7 100644 (file)
@@ -21,7 +21,7 @@
 #include <linux/module.h>
 #include <linux/mutex.h>
 #include <linux/percpu.h>
-#include <linux/rtnetlink.h>
+#include <linux/slab.h>
 #include <linux/smp.h>
 #include <linux/vmalloc.h>
 #include <net/ip.h>
 
 struct ipcomp_tfms {
        struct list_head list;
-       struct crypto_comp **tfms;
+       struct crypto_comp * __percpu *tfms;
        int users;
 };
 
 static DEFINE_MUTEX(ipcomp_resource_mutex);
-static void **ipcomp_scratches;
+static void * __percpu *ipcomp_scratches;
 static int ipcomp_scratch_users;
 static LIST_HEAD(ipcomp_tfms_list);
 
@@ -49,6 +49,7 @@ static int ipcomp_decompress(struct xfrm_state *x, struct sk_buff *skb)
        u8 *scratch = *per_cpu_ptr(ipcomp_scratches, cpu);
        struct crypto_comp *tfm = *per_cpu_ptr(ipcd->tfms, cpu);
        int err = crypto_comp_decompress(tfm, start, plen, scratch, &dlen);
+       int len;
 
        if (err)
                goto out;
@@ -58,13 +59,46 @@ static int ipcomp_decompress(struct xfrm_state *x, struct sk_buff *skb)
                goto out;
        }
 
-       err = pskb_expand_head(skb, 0, dlen - plen, GFP_ATOMIC);
-       if (err)
-               goto out;
+       len = dlen - plen;
+       if (len > skb_tailroom(skb))
+               len = skb_tailroom(skb);
+
+       __skb_put(skb, len);
+
+       len += plen;
+       skb_copy_to_linear_data(skb, scratch, len);
+
+       while ((scratch += len, dlen -= len) > 0) {
+               skb_frag_t *frag;
+
+               err = -EMSGSIZE;
+               if (WARN_ON(skb_shinfo(skb)->nr_frags >= MAX_SKB_FRAGS))
+                       goto out;
+
+               frag = skb_shinfo(skb)->frags + skb_shinfo(skb)->nr_frags;
+               frag->page = alloc_page(GFP_ATOMIC);
+
+               err = -ENOMEM;
+               if (!frag->page)
+                       goto out;
+
+               len = PAGE_SIZE;
+               if (dlen < len)
+                       len = dlen;
+
+               memcpy(page_address(frag->page), scratch, len);
+
+               frag->page_offset = 0;
+               frag->size = len;
+               skb->truesize += len;
+               skb->data_len += len;
+               skb->len += len;
+
+               skb_shinfo(skb)->nr_frags++;
+       }
+
+       err = 0;
 
-       skb->truesize += dlen - plen;
-       __skb_put(skb, dlen - plen);
-       skb_copy_to_linear_data(skb, scratch, dlen);
 out:
        put_cpu();
        return err;
@@ -166,7 +200,7 @@ EXPORT_SYMBOL_GPL(ipcomp_output);
 static void ipcomp_free_scratches(void)
 {
        int i;
-       void **scratches;
+       void * __percpu *scratches;
 
        if (--ipcomp_scratch_users)
                return;
@@ -181,10 +215,10 @@ static void ipcomp_free_scratches(void)
        free_percpu(scratches);
 }
 
-static void **ipcomp_alloc_scratches(void)
+static void * __percpu *ipcomp_alloc_scratches(void)
 {
        int i;
-       void **scratches;
+       void * __percpu *scratches;
 
        if (ipcomp_scratch_users++)
                return ipcomp_scratches;
@@ -205,7 +239,7 @@ static void **ipcomp_alloc_scratches(void)
        return scratches;
 }
 
-static void ipcomp_free_tfms(struct crypto_comp **tfms)
+static void ipcomp_free_tfms(struct crypto_comp * __percpu *tfms)
 {
        struct ipcomp_tfms *pos;
        int cpu;
@@ -215,7 +249,7 @@ static void ipcomp_free_tfms(struct crypto_comp **tfms)
                        break;
        }
 
-       BUG_TRAP(pos);
+       WARN_ON(!pos);
 
        if (--pos->users)
                return;
@@ -233,10 +267,10 @@ static void ipcomp_free_tfms(struct crypto_comp **tfms)
        free_percpu(tfms);
 }
 
-static struct crypto_comp **ipcomp_alloc_tfms(const char *alg_name)
+static struct crypto_comp * __percpu *ipcomp_alloc_tfms(const char *alg_name)
 {
        struct ipcomp_tfms *pos;
-       struct crypto_comp **tfms;
+       struct crypto_comp * __percpu *tfms;
        int cpu;
 
        /* This can be any valid CPU ID so we don't need locking. */