2010-01-06 16:54:21

by Jiri Slaby

[permalink] [raw]
Subject: [PATCH 1/1] NET: atlx, fix memory leak

Stanse found a memory leak in atl2_get_eeprom. eeprom_buff is not
freed/assigned on all paths. Fix that.

Signed-off-by: Jiri Slaby <[email protected]>
Cc: Jay Cliburn <[email protected]>
Cc: Chris Snook <[email protected]>
Cc: Jie Yang <[email protected]>
Cc: [email protected]
Cc: "David S. Miller" <[email protected]>
Cc: [email protected]
---
drivers/net/atlx/atl2.c | 7 +++++--
1 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/net/atlx/atl2.c b/drivers/net/atlx/atl2.c
index c0451d7..ec52529 100644
--- a/drivers/net/atlx/atl2.c
+++ b/drivers/net/atlx/atl2.c
@@ -1959,12 +1959,15 @@ static int atl2_get_eeprom(struct net_device *netdev,
return -ENOMEM;

for (i = first_dword; i < last_dword; i++) {
- if (!atl2_read_eeprom(hw, i*4, &(eeprom_buff[i-first_dword])))
- return -EIO;
+ if (!atl2_read_eeprom(hw, i*4, &(eeprom_buff[i-first_dword]))) {
+ ret_val = -EIO;
+ goto free;
+ }
}

memcpy(bytes, (u8 *)eeprom_buff + (eeprom->offset & 3),
eeprom->len);
+free:
kfree(eeprom_buff);

return ret_val;
--
1.6.5.7


2010-01-07 00:28:38

by J. K. Cliburn

[permalink] [raw]
Subject: Re: [PATCH 1/1] NET: atlx, fix memory leak

On Wed, 6 Jan 2010 17:54:16 +0100
Jiri Slaby <[email protected]> wrote:

> Stanse found a memory leak in atl2_get_eeprom. eeprom_buff is not
> freed/assigned on all paths. Fix that.

Acked by: Jay Cliburn <[email protected]>

>
> Signed-off-by: Jiri Slaby <[email protected]>
> Cc: Jay Cliburn <[email protected]>
> Cc: Chris Snook <[email protected]>
> Cc: Jie Yang <[email protected]>
> Cc: [email protected]
> Cc: "David S. Miller" <[email protected]>
> Cc: [email protected]
> ---
> drivers/net/atlx/atl2.c | 7 +++++--
> 1 files changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/net/atlx/atl2.c b/drivers/net/atlx/atl2.c
> index c0451d7..ec52529 100644
> --- a/drivers/net/atlx/atl2.c
> +++ b/drivers/net/atlx/atl2.c
> @@ -1959,12 +1959,15 @@ static int atl2_get_eeprom(struct net_device
> *netdev, return -ENOMEM;
>
> for (i = first_dword; i < last_dword; i++) {
> - if (!atl2_read_eeprom(hw, i*4,
> &(eeprom_buff[i-first_dword])))
> - return -EIO;
> + if (!atl2_read_eeprom(hw, i*4,
> &(eeprom_buff[i-first_dword]))) {
> + ret_val = -EIO;
> + goto free;
> + }
> }
>
> memcpy(bytes, (u8 *)eeprom_buff + (eeprom->offset & 3),
> eeprom->len);
> +free:
> kfree(eeprom_buff);
>
> return ret_val;

2010-01-07 09:05:03

by David Miller

[permalink] [raw]
Subject: Re: [PATCH 1/1] NET: atlx, fix memory leak

From: J K Cliburn <[email protected]>
Date: Wed, 6 Jan 2010 18:28:30 -0600

> On Wed, 6 Jan 2010 17:54:16 +0100
> Jiri Slaby <[email protected]> wrote:
>
>> Stanse found a memory leak in atl2_get_eeprom. eeprom_buff is not
>> freed/assigned on all paths. Fix that.
>
> Acked by: Jay Cliburn <[email protected]>

Applied, thanks.