bnx2: Refine VPD logic.
[safe/jmp/linux-2.6] / drivers / net / ppp_deflate.c
index 507d632..695bc83 100644 (file)
@@ -87,8 +87,7 @@ static void z_comp_free(void *arg)
 
        if (state) {
                zlib_deflateEnd(&state->strm);
-               if (state->strm.workspace)
-                       vfree(state->strm.workspace);
+               vfree(state->strm.workspace);
                kfree(state);
        }
 }
@@ -112,22 +111,21 @@ static void *z_comp_alloc(unsigned char *options, int opt_len)
        struct ppp_deflate_state *state;
        int w_size;
 
-       if (opt_len != CILEN_DEFLATE
-           || (options[0] != CI_DEFLATE && options[0] != CI_DEFLATE_DRAFT)
-           || options[1] != CILEN_DEFLATE
-           || DEFLATE_METHOD(options[2]) != DEFLATE_METHOD_VAL
-           || options[3] != DEFLATE_CHK_SEQUENCE)
+       if (opt_len != CILEN_DEFLATE ||
+           (options[0] != CI_DEFLATE && options[0] != CI_DEFLATE_DRAFT) ||
+           options[1] != CILEN_DEFLATE ||
+           DEFLATE_METHOD(options[2]) != DEFLATE_METHOD_VAL ||
+           options[3] != DEFLATE_CHK_SEQUENCE)
                return NULL;
        w_size = DEFLATE_SIZE(options[2]);
        if (w_size < DEFLATE_MIN_SIZE || w_size > DEFLATE_MAX_SIZE)
                return NULL;
 
-       state = (struct ppp_deflate_state *) kmalloc(sizeof(*state),
+       state = kzalloc(sizeof(*state),
                                                     GFP_KERNEL);
        if (state == NULL)
                return NULL;
 
-       memset (state, 0, sizeof (struct ppp_deflate_state));
        state->strm.next_in   = NULL;
        state->w_size         = w_size;
        state->strm.workspace = vmalloc(zlib_deflate_workspacesize());
@@ -165,12 +163,12 @@ static int z_comp_init(void *arg, unsigned char *options, int opt_len,
 {
        struct ppp_deflate_state *state = (struct ppp_deflate_state *) arg;
 
-       if (opt_len < CILEN_DEFLATE
-           || (options[0] != CI_DEFLATE && options[0] != CI_DEFLATE_DRAFT)
-           || options[1] != CILEN_DEFLATE
-           || DEFLATE_METHOD(options[2]) != DEFLATE_METHOD_VAL
-           || DEFLATE_SIZE(options[2]) != state->w_size
-           || options[3] != DEFLATE_CHK_SEQUENCE)
+       if (opt_len < CILEN_DEFLATE ||
+           (options[0] != CI_DEFLATE && options[0] != CI_DEFLATE_DRAFT) ||
+           options[1] != CILEN_DEFLATE ||
+           DEFLATE_METHOD(options[2]) != DEFLATE_METHOD_VAL ||
+           DEFLATE_SIZE(options[2]) != state->w_size ||
+           options[3] != DEFLATE_CHK_SEQUENCE)
                return 0;
 
        state->seqno = 0;
@@ -208,7 +206,7 @@ static void z_comp_reset(void *arg)
  *     Returns the length of the compressed packet, or 0 if the
  *     packet is incompressible.
  */
-int z_compress(void *arg, unsigned char *rptr, unsigned char *obuf,
+static int z_compress(void *arg, unsigned char *rptr, unsigned char *obuf,
               int isize, int osize)
 {
        struct ppp_deflate_state *state = (struct ppp_deflate_state *) arg;
@@ -308,8 +306,7 @@ static void z_decomp_free(void *arg)
 
        if (state) {
                zlib_inflateEnd(&state->strm);
-               if (state->strm.workspace)
-                       kfree(state->strm.workspace);
+               kfree(state->strm.workspace);
                kfree(state);
        }
 }
@@ -333,21 +330,20 @@ static void *z_decomp_alloc(unsigned char *options, int opt_len)
        struct ppp_deflate_state *state;
        int w_size;
 
-       if (opt_len != CILEN_DEFLATE
-           || (options[0] != CI_DEFLATE && options[0] != CI_DEFLATE_DRAFT)
-           || options[1] != CILEN_DEFLATE
-           || DEFLATE_METHOD(options[2]) != DEFLATE_METHOD_VAL
-           || options[3] != DEFLATE_CHK_SEQUENCE)
+       if (opt_len != CILEN_DEFLATE ||
+           (options[0] != CI_DEFLATE && options[0] != CI_DEFLATE_DRAFT) ||
+           options[1] != CILEN_DEFLATE ||
+           DEFLATE_METHOD(options[2]) != DEFLATE_METHOD_VAL ||
+           options[3] != DEFLATE_CHK_SEQUENCE)
                return NULL;
        w_size = DEFLATE_SIZE(options[2]);
        if (w_size < DEFLATE_MIN_SIZE || w_size > DEFLATE_MAX_SIZE)
                return NULL;
 
-       state = (struct ppp_deflate_state *) kmalloc(sizeof(*state), GFP_KERNEL);
+       state = kzalloc(sizeof(*state), GFP_KERNEL);
        if (state == NULL)
                return NULL;
 
-       memset (state, 0, sizeof (struct ppp_deflate_state));
        state->w_size         = w_size;
        state->strm.next_out  = NULL;
        state->strm.workspace = kmalloc(zlib_inflate_workspacesize(),
@@ -385,12 +381,12 @@ static int z_decomp_init(void *arg, unsigned char *options, int opt_len,
 {
        struct ppp_deflate_state *state = (struct ppp_deflate_state *) arg;
 
-       if (opt_len < CILEN_DEFLATE
-           || (options[0] != CI_DEFLATE && options[0] != CI_DEFLATE_DRAFT)
-           || options[1] != CILEN_DEFLATE
-           || DEFLATE_METHOD(options[2]) != DEFLATE_METHOD_VAL
-           || DEFLATE_SIZE(options[2]) != state->w_size
-           || options[3] != DEFLATE_CHK_SEQUENCE)
+       if (opt_len < CILEN_DEFLATE ||
+           (options[0] != CI_DEFLATE && options[0] != CI_DEFLATE_DRAFT) ||
+           options[1] != CILEN_DEFLATE ||
+           DEFLATE_METHOD(options[2]) != DEFLATE_METHOD_VAL ||
+           DEFLATE_SIZE(options[2]) != state->w_size ||
+           options[3] != DEFLATE_CHK_SEQUENCE)
                return 0;
 
        state->seqno = 0;
@@ -439,7 +435,7 @@ static void z_decomp_reset(void *arg)
  * bug, so we return DECOMP_FATALERROR for them in order to turn off
  * compression, even though they are detected by inspecting the input.
  */
-int z_decompress(void *arg, unsigned char *ibuf, int isize,
+static int z_decompress(void *arg, unsigned char *ibuf, int isize,
                 unsigned char *obuf, int osize)
 {
        struct ppp_deflate_state *state = (struct ppp_deflate_state *) arg;
@@ -637,7 +633,7 @@ static struct compressor ppp_deflate_draft = {
 };
 
 static int __init deflate_init(void)
-{  
+{
         int answer = ppp_register_compressor(&ppp_deflate);
         if (answer == 0)
                 printk(KERN_INFO
@@ -645,7 +641,7 @@ static int __init deflate_init(void)
        ppp_register_compressor(&ppp_deflate_draft);
         return answer;
 }
-     
+
 static void __exit deflate_cleanup(void)
 {
        ppp_unregister_compressor(&ppp_deflate);