switch: fix some memory leaks in switch_parse_vlan()
authorHauke Mehrtens <hauke@hauke-m.de>
Sat, 28 Jan 2012 13:52:37 +0000 (13:52 +0000)
committerHauke Mehrtens <hauke@hauke-m.de>
Sat, 28 Jan 2012 13:52:37 +0000 (13:52 +0000)
SVN-Revision: 29936

package/switch/src/switch-adm.c
package/switch/src/switch-core.c
package/switch/src/switch-robo.c

index 2aff14207b380aa0b19e1c1d02042b9e96cd99ca..3826ca57f847ac8b672ab8b5afdc16ad627bc031 100644 (file)
@@ -341,6 +341,7 @@ static int handle_vlan_port_write(void *driver, char *buf, int nr)
        }
        adm_wreg(0x13 + nr, (__u16) ports);
 
+       kfree(c);
        return 0;
 }
 
index f5b248aadbb2b60bbc15e06a38c7c9c7ba847458..79b4e93f03ca99e3a8b3f9ddeb4dffb8163c8481 100644 (file)
@@ -341,10 +341,9 @@ switch_vlan_config *switch_parse_vlan(switch_driver *driver, char *buf)
        switch_vlan_config *c;
        int j, u, p, s;
 
-       c = kmalloc(sizeof(switch_vlan_config), GFP_KERNEL);
+       c = kzalloc(sizeof(switch_vlan_config), GFP_KERNEL);
        if (!c)
                return NULL;
-       memset(c, 0, sizeof(switch_vlan_config));
 
        while (isspace(*buf)) buf++;
        j = 0;
@@ -382,7 +381,10 @@ switch_vlan_config *switch_parse_vlan(switch_driver *driver, char *buf)
 
                while (isspace(*buf)) buf++;
        }
-       if (*buf != 0) return NULL;
+       if (*buf != 0) {
+               kfree(c);
+               return NULL;
+       }
 
        c->port &= (1 << driver->ports) - 1;
        c->untag &= (1 << driver->ports) - 1;
index ec9e3373375ac3dea59359121430969a51c6aad3..7bac91942a098d0e9371a12e8533c90a0b8e2de2 100644 (file)
@@ -459,6 +459,7 @@ static int handle_vlan_port_write(void *driver, char *buf, int nr)
                robo_write32(ROBO_ARLIO_PAGE, 0x63 + regoff, (c->untag << 9) | c->port);
                robo_write16(ROBO_ARLIO_PAGE, 0x61 + regoff, nr);
                robo_write16(ROBO_ARLIO_PAGE, 0x60 + regoff, 1 << 7);
+               kfree(c);
                return 0;
        }
 
@@ -473,6 +474,7 @@ static int handle_vlan_port_write(void *driver, char *buf, int nr)
                robo_write16(ROBO_VLAN_PAGE, ROBO_VLAN_TABLE_ACCESS, val16);
        }
 
+       kfree(c);
        return 0;
 }
 
@@ -520,13 +522,9 @@ static int handle_enable_vlan_write(void *driver, char *buf, int nr)
 static int handle_reset(void *driver, char *buf, int nr)
 {
        switch_driver *d = (switch_driver *) driver;
-       switch_vlan_config *c = switch_parse_vlan(d, buf);
        int j;
        __u16 val16;
 
-       if (c == NULL)
-               return -EINVAL;
-
        /* disable switching */
        set_switch(0);