diff mbox series

[U-Boot] ata: ahci: fix memory leak

Message ID 20190506131854.19786-1-christian.gmeiner@gmail.com
State Accepted
Commit 28b4ba94811122d7a91924f62d63d8b25bfa979c
Delegated to: Tom Rini
Headers show
Series [U-Boot] ata: ahci: fix memory leak | expand

Commit Message

Christian Gmeiner May 6, 2019, 1:18 p.m. UTC
malloc(..) and memalign(..) are both allocating memory and as a result
we leak the memory allocated with malloc(..).

Signed-off-by: Christian Gmeiner <christian.gmeiner@gmail.com>
---
 drivers/ata/ahci.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

Comments

Simon Glass May 6, 2019, 5:06 p.m. UTC | #1
On Mon, 6 May 2019 at 07:18, Christian Gmeiner
<christian.gmeiner@gmail.com> wrote:
>
> malloc(..) and memalign(..) are both allocating memory and as a result
> we leak the memory allocated with malloc(..).
>
> Signed-off-by: Christian Gmeiner <christian.gmeiner@gmail.com>
> ---
>  drivers/ata/ahci.c | 5 +----
>  1 file changed, 1 insertion(+), 4 deletions(-)
>

Reviewed-by: Simon Glass <sjg@chromium.org>
Tom Rini May 10, 2019, 11:11 a.m. UTC | #2
On Mon, May 06, 2019 at 03:18:54PM +0200, Christian Gmeiner wrote:

> malloc(..) and memalign(..) are both allocating memory and as a result
> we leak the memory allocated with malloc(..).
> 
> Signed-off-by: Christian Gmeiner <christian.gmeiner@gmail.com>
> Reviewed-by: Simon Glass <sjg@chromium.org>

Applied to u-boot/master, thanks!
diff mbox series

Patch

diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c
index 5fafb63aeb..188d843197 100644
--- a/drivers/ata/ahci.c
+++ b/drivers/ata/ahci.c
@@ -571,15 +571,12 @@  static int ahci_port_start(struct ahci_uc_priv *uc_priv, u8 port)
 		return -1;
 	}
 
-	mem = malloc(AHCI_PORT_PRIV_DMA_SZ + 2048);
+	mem = memalign(2048, AHCI_PORT_PRIV_DMA_SZ);
 	if (!mem) {
 		free(pp);
 		printf("%s: No mem for table!\n", __func__);
 		return -ENOMEM;
 	}
-
-	/* Aligned to 2048-bytes */
-	mem = memalign(2048, AHCI_PORT_PRIV_DMA_SZ);
 	memset(mem, 0, AHCI_PORT_PRIV_DMA_SZ);
 
 	/*