提交 ad19031b 编写于 作者: J Jesper Juhl 提交者: David S. Miller

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: NJesper Juhl <jj@chaosbits.net>
Signed-off-by: NDavid S. Miller <davem@davemloft.net>
上级 79b569f0
...@@ -1996,13 +1996,15 @@ static int atl2_set_eeprom(struct net_device *netdev, ...@@ -1996,13 +1996,15 @@ static int atl2_set_eeprom(struct net_device *netdev,
if (!eeprom_buff) if (!eeprom_buff)
return -ENOMEM; return -ENOMEM;
ptr = (u32 *)eeprom_buff; ptr = eeprom_buff;
if (eeprom->offset & 3) { if (eeprom->offset & 3) {
/* need read/modify/write of first changed EEPROM word */ /* need read/modify/write of first changed EEPROM word */
/* only the second byte of the word is being modified */ /* only the second byte of the word is being modified */
if (!atl2_read_eeprom(hw, first_dword*4, &(eeprom_buff[0]))) if (!atl2_read_eeprom(hw, first_dword*4, &(eeprom_buff[0]))) {
return -EIO; ret_val = -EIO;
goto out;
}
ptr++; ptr++;
} }
if (((eeprom->offset + eeprom->len) & 3)) { if (((eeprom->offset + eeprom->len) & 3)) {
...@@ -2011,18 +2013,22 @@ static int atl2_set_eeprom(struct net_device *netdev, ...@@ -2011,18 +2013,22 @@ static int atl2_set_eeprom(struct net_device *netdev,
* only the first byte of the word is being modified * only the first byte of the word is being modified
*/ */
if (!atl2_read_eeprom(hw, last_dword * 4, if (!atl2_read_eeprom(hw, last_dword * 4,
&(eeprom_buff[last_dword - first_dword]))) &(eeprom_buff[last_dword - first_dword]))) {
return -EIO; ret_val = -EIO;
goto out;
}
} }
/* Device's eeprom is always little-endian, word addressable */ /* Device's eeprom is always little-endian, word addressable */
memcpy(ptr, bytes, eeprom->len); memcpy(ptr, bytes, eeprom->len);
for (i = 0; i < last_dword - first_dword + 1; i++) { for (i = 0; i < last_dword - first_dword + 1; i++) {
if (!atl2_write_eeprom(hw, ((first_dword+i)*4), eeprom_buff[i])) if (!atl2_write_eeprom(hw, ((first_dword+i)*4), eeprom_buff[i])) {
return -EIO; ret_val = -EIO;
goto out;
}
} }
out:
kfree(eeprom_buff); kfree(eeprom_buff);
return ret_val; return ret_val;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册