diff options
author | Jesper Juhl <jj@chaosbits.net> | 2011-03-27 05:16:12 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2011-03-30 05:42:25 -0400 |
commit | ad19031b5f6ede5b2df057e3e1b4f82a2ef7f75f (patch) | |
tree | 1ec06208e25e6d39c0857d55ef4d1657dfba411d /drivers/net/atlx | |
parent | 79b569f0ec53a14c4d71e79d93a8676d9a0fda6d (diff) |
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 <jj@chaosbits.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/atlx')
-rw-r--r-- | drivers/net/atlx/atl2.c | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/drivers/net/atlx/atl2.c b/drivers/net/atlx/atl2.c index e637e9f28fd4..937ef1afa5db 100644 --- a/drivers/net/atlx/atl2.c +++ b/drivers/net/atlx/atl2.c | |||
@@ -1996,13 +1996,15 @@ static int atl2_set_eeprom(struct net_device *netdev, | |||
1996 | if (!eeprom_buff) | 1996 | if (!eeprom_buff) |
1997 | return -ENOMEM; | 1997 | return -ENOMEM; |
1998 | 1998 | ||
1999 | ptr = (u32 *)eeprom_buff; | 1999 | ptr = eeprom_buff; |
2000 | 2000 | ||
2001 | if (eeprom->offset & 3) { | 2001 | if (eeprom->offset & 3) { |
2002 | /* need read/modify/write of first changed EEPROM word */ | 2002 | /* need read/modify/write of first changed EEPROM word */ |
2003 | /* only the second byte of the word is being modified */ | 2003 | /* only the second byte of the word is being modified */ |
2004 | if (!atl2_read_eeprom(hw, first_dword*4, &(eeprom_buff[0]))) | 2004 | if (!atl2_read_eeprom(hw, first_dword*4, &(eeprom_buff[0]))) { |
2005 | return -EIO; | 2005 | ret_val = -EIO; |
2006 | goto out; | ||
2007 | } | ||
2006 | ptr++; | 2008 | ptr++; |
2007 | } | 2009 | } |
2008 | if (((eeprom->offset + eeprom->len) & 3)) { | 2010 | if (((eeprom->offset + eeprom->len) & 3)) { |
@@ -2011,18 +2013,22 @@ static int atl2_set_eeprom(struct net_device *netdev, | |||
2011 | * only the first byte of the word is being modified | 2013 | * only the first byte of the word is being modified |
2012 | */ | 2014 | */ |
2013 | if (!atl2_read_eeprom(hw, last_dword * 4, | 2015 | if (!atl2_read_eeprom(hw, last_dword * 4, |
2014 | &(eeprom_buff[last_dword - first_dword]))) | 2016 | &(eeprom_buff[last_dword - first_dword]))) { |
2015 | return -EIO; | 2017 | ret_val = -EIO; |
2018 | goto out; | ||
2019 | } | ||
2016 | } | 2020 | } |
2017 | 2021 | ||
2018 | /* Device's eeprom is always little-endian, word addressable */ | 2022 | /* Device's eeprom is always little-endian, word addressable */ |
2019 | memcpy(ptr, bytes, eeprom->len); | 2023 | memcpy(ptr, bytes, eeprom->len); |
2020 | 2024 | ||
2021 | for (i = 0; i < last_dword - first_dword + 1; i++) { | 2025 | for (i = 0; i < last_dword - first_dword + 1; i++) { |
2022 | if (!atl2_write_eeprom(hw, ((first_dword+i)*4), eeprom_buff[i])) | 2026 | if (!atl2_write_eeprom(hw, ((first_dword+i)*4), eeprom_buff[i])) { |
2023 | return -EIO; | 2027 | ret_val = -EIO; |
2028 | goto out; | ||
2029 | } | ||
2024 | } | 2030 | } |
2025 | 2031 | out: | |
2026 | kfree(eeprom_buff); | 2032 | kfree(eeprom_buff); |
2027 | return ret_val; | 2033 | return ret_val; |
2028 | } | 2034 | } |