Atheros, atl2: Fix mem leaks in error paths of atl2_set_eeprom
authorJesper Juhl <jj@chaosbits.net>
Sun, 27 Mar 2011 09:16:12 +0000 (09:16 +0000)
committerDavid S. Miller <davem@davemloft.net>
Wed, 30 Mar 2011 09:42:25 +0000 (02:42 -0700)
We leak in some error paths of drivers/net/atlx/atl2.c:atl2_set_eeprom().
The memory allocated to 'eeprom_buff' is not freed when we return -EIO.
This patch fixes that up and also removes a pointless explicit cast.

Signed-off-by: Jesper Juhl <jj@chaosbits.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/atlx/atl2.c

index e637e9f28fd4456612aa8b2b1b47c8cf670acb81..937ef1afa5db873397c821392153d1f5ebc3ff32 100644 (file)
@@ -1996,13 +1996,15 @@ static int atl2_set_eeprom(struct net_device *netdev,
        if (!eeprom_buff)
                return -ENOMEM;
 
-       ptr = (u32 *)eeprom_buff;
+       ptr = eeprom_buff;
 
        if (eeprom->offset & 3) {
                /* need read/modify/write of first changed EEPROM word */
                /* only the second byte of the word is being modified */
-               if (!atl2_read_eeprom(hw, first_dword*4, &(eeprom_buff[0])))
-                       return -EIO;
+               if (!atl2_read_eeprom(hw, first_dword*4, &(eeprom_buff[0]))) {
+                       ret_val = -EIO;
+                       goto out;
+               }
                ptr++;
        }
        if (((eeprom->offset + eeprom->len) & 3)) {
@@ -2011,18 +2013,22 @@ static int atl2_set_eeprom(struct net_device *netdev,
                 * only the first byte of the word is being modified
                 */
                if (!atl2_read_eeprom(hw, last_dword * 4,
-                       &(eeprom_buff[last_dword - first_dword])))
-                       return -EIO;
+                                       &(eeprom_buff[last_dword - first_dword]))) {
+                       ret_val = -EIO;
+                       goto out;
+               }
        }
 
        /* Device's eeprom is always little-endian, word addressable */
        memcpy(ptr, bytes, eeprom->len);
 
        for (i = 0; i < last_dword - first_dword + 1; i++) {
-               if (!atl2_write_eeprom(hw, ((first_dword+i)*4), eeprom_buff[i]))
-                       return -EIO;
+               if (!atl2_write_eeprom(hw, ((first_dword+i)*4), eeprom_buff[i])) {
+                       ret_val = -EIO;
+                       goto out;
+               }
        }
-
+ out:
        kfree(eeprom_buff);
        return ret_val;
 }