ibmveth: Add suspend/resume support
[safe/jmp/linux-2.6] / drivers / net / slhc.c
index 3a1b713..ac279fa 100644 (file)
@@ -42,7 +42,7 @@
  *                      Modularization.
  *     - Jan 1995      Bjorn Ekwall
  *                     Use ip_fast_csum from ip.h
- *     - July 1995     Christos A. Polyzols 
+ *     - July 1995     Christos A. Polyzols
  *                     Spotted bug in tcp option checking
  *
  *
@@ -51,6 +51,7 @@
  */
 
 #include <linux/module.h>
+#include <linux/slab.h>
 #include <linux/types.h>
 #include <linux/string.h>
 #include <linux/errno.h>
@@ -94,27 +95,23 @@ slhc_init(int rslots, int tslots)
        register struct cstate *ts;
        struct slcompress *comp;
 
-       comp = (struct slcompress *)kmalloc(sizeof(struct slcompress),
-                                           GFP_KERNEL);
+       comp = kzalloc(sizeof(struct slcompress), GFP_KERNEL);
        if (! comp)
                goto out_fail;
-       memset(comp, 0, sizeof(struct slcompress));
 
        if ( rslots > 0  &&  rslots < 256 ) {
                size_t rsize = rslots * sizeof(struct cstate);
-               comp->rstate = (struct cstate *) kmalloc(rsize, GFP_KERNEL);
+               comp->rstate = kzalloc(rsize, GFP_KERNEL);
                if (! comp->rstate)
                        goto out_free;
-               memset(comp->rstate, 0, rsize);
                comp->rslot_limit = rslots - 1;
        }
 
        if ( tslots > 0  &&  tslots < 256 ) {
                size_t tsize = tslots * sizeof(struct cstate);
-               comp->tstate = (struct cstate *) kmalloc(tsize, GFP_KERNEL);
+               comp->tstate = kzalloc(tsize, GFP_KERNEL);
                if (! comp->tstate)
                        goto out_free2;
-               memset(comp->tstate, 0, tsize);
                comp->tslot_limit = tslots - 1;
        }
 
@@ -141,9 +138,9 @@ slhc_init(int rslots, int tslots)
        return comp;
 
 out_free2:
-       kfree((unsigned char *)comp->rstate);
+       kfree(comp->rstate);
 out_free:
-       kfree((unsigned char *)comp);
+       kfree(comp);
 out_fail:
        return NULL;
 }
@@ -178,7 +175,7 @@ put16(unsigned char *cp, unsigned short x)
 
 
 /* Encode a number */
-unsigned char *
+static unsigned char *
 encode(unsigned char *cp, unsigned short n)
 {
        if(n >= 256 || n == 0){
@@ -203,7 +200,7 @@ pull16(unsigned char **cpp)
 }
 
 /* Decode a number */
-long
+static long
 decode(unsigned char **cpp)
 {
        register int x;
@@ -237,15 +234,16 @@ slhc_compress(struct slcompress *comp, unsigned char *icp, int isize,
        register unsigned char *cp = new_seq;
        struct iphdr *ip;
        struct tcphdr *th, *oth;
+       __sum16 csum;
 
 
        /*
         *      Don't play with runt packets.
         */
-        
+
        if(isize<sizeof(struct iphdr))
                return isize;
-               
+
        ip = (struct iphdr *) icp;
 
        /* Bail if this packet isn't TCP, or is an IP fragment */
@@ -432,7 +430,7 @@ found:
        /* Grab the cksum before we overwrite it below.  Then update our
         * state with this packet's header.
         */
-       deltaA = ntohs(th->check);
+       csum = th->check;
        memcpy(&cs->cs_ip,ip,20);
        memcpy(&cs->cs_tcp,th,20);
        /* We want to use the original packet as our compressed packet.
@@ -453,7 +451,8 @@ found:
                *cpp = ocp;
                *cp++ = changes;
        }
-       cp = put16(cp,(short)deltaA);   /* Write TCP checksum */
+       *(__sum16 *)cp = csum;
+       cp += 2;
 /* deltaS is now the size of the change section of the compressed header */
        memcpy(cp,new_seq,deltaS);      /* Write list of deltas */
        memcpy(cp+deltaS,icp+hlen,isize-hlen);
@@ -523,10 +522,8 @@ slhc_uncompress(struct slcompress *comp, unsigned char *icp, int isize)
        thp = &cs->cs_tcp;
        ip = &cs->cs_ip;
 
-       if((x = pull16(&cp)) == -1) {   /* Read the TCP checksum */
-               goto bad;
-        }
-       thp->check = htons(x);
+       thp->check = *(__sum16 *)cp;
+       cp += 2;
 
        thp->psh = (changes & TCP_PUSH_BIT) ? 1 : 0;
 /*
@@ -700,20 +697,6 @@ EXPORT_SYMBOL(slhc_compress);
 EXPORT_SYMBOL(slhc_uncompress);
 EXPORT_SYMBOL(slhc_toss);
 
-#ifdef MODULE
-
-int init_module(void)
-{
-       printk(KERN_INFO "CSLIP: code copyright 1989 Regents of the University of California\n");
-       return 0;
-}
-
-void cleanup_module(void)
-{
-       return;
-}
-
-#endif /* MODULE */
 #else /* CONFIG_INET */
 
 
@@ -748,7 +731,6 @@ void
 slhc_free(struct slcompress *comp)
 {
   printk(KERN_DEBUG "Called IP function on non IP-system: slhc_free");
-  return;
 }
 struct slcompress *
 slhc_init(int rslots, int tslots)