Skip to content

Commit ad19031

Browse files
jjuhldavem330
authored andcommitted
Atheros, atl2: Fix mem leaks in error paths of atl2_set_eeprom
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 <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 79b569f commit ad19031

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

drivers/net/atlx/atl2.c

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1996,13 +1996,15 @@ static int atl2_set_eeprom(struct net_device *netdev,
19961996
if (!eeprom_buff)
19971997
return -ENOMEM;
19981998

1999-
ptr = (u32 *)eeprom_buff;
1999+
ptr = eeprom_buff;
20002000

20012001
if (eeprom->offset & 3) {
20022002
/* need read/modify/write of first changed EEPROM word */
20032003
/* only the second byte of the word is being modified */
2004-
if (!atl2_read_eeprom(hw, first_dword*4, &(eeprom_buff[0])))
2005-
return -EIO;
2004+
if (!atl2_read_eeprom(hw, first_dword*4, &(eeprom_buff[0]))) {
2005+
ret_val = -EIO;
2006+
goto out;
2007+
}
20062008
ptr++;
20072009
}
20082010
if (((eeprom->offset + eeprom->len) & 3)) {
@@ -2011,18 +2013,22 @@ static int atl2_set_eeprom(struct net_device *netdev,
20112013
* only the first byte of the word is being modified
20122014
*/
20132015
if (!atl2_read_eeprom(hw, last_dword * 4,
2014-
&(eeprom_buff[last_dword - first_dword])))
2015-
return -EIO;
2016+
&(eeprom_buff[last_dword - first_dword]))) {
2017+
ret_val = -EIO;
2018+
goto out;
2019+
}
20162020
}
20172021

20182022
/* Device's eeprom is always little-endian, word addressable */
20192023
memcpy(ptr, bytes, eeprom->len);
20202024

20212025
for (i = 0; i < last_dword - first_dword + 1; i++) {
2022-
if (!atl2_write_eeprom(hw, ((first_dword+i)*4), eeprom_buff[i]))
2023-
return -EIO;
2026+
if (!atl2_write_eeprom(hw, ((first_dword+i)*4), eeprom_buff[i])) {
2027+
ret_val = -EIO;
2028+
goto out;
2029+
}
20242030
}
2025-
2031+
out:
20262032
kfree(eeprom_buff);
20272033
return ret_val;
20282034
}

0 commit comments

Comments
 (0)