Skip to contentSkip to conversation

ata: ahci: remove bad free

PATCH In review Vincent Stehlé 3 participants 3 messages Mar 24, 2025 – Apr 10, 2025 libata

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ata: ahci: remove bad free

In the case of a memory allocation error, the ahci_port_start() function tries to free the `pp' pointer.
This pointer was not dynamically allocated but does in fact point to an element of the port[] array member of the struct ahci_uc_priv. Remove the erroneous call to free() to fix this.

Fixes 4782ac80b02f ("Add AHCI support to u-boot")
Cc Tom Rini <[email protected]>
Cc Jason Jin <[email protected]>
---
 drivers/ata/ahci.c | 1 -
 1 file changed, 1 deletion(-)
drivers/ata/ahci.c +0 -1
index 8058d5ff1c3..e593e228685 100644
@@ -463,7 +463,6 @@ static int ahci_port_start(struct ahci_uc_priv *uc_priv, u8 port)
 
 	mem = memalign(2048, AHCI_PORT_PRIV_DMA_SZ);
 	if (!mem) {
-		free(pp);
 		printf("%s: No mem for table!\n", __func__);
 		return -ENOMEM;
 	}
Signature · 1 line
2.47.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · On Mon, 24 Mar 2025 09:34:06 +0100 Vincent Stehlé <[email protected]>…

In the case of a memory allocation error, the ahci_port_start() function tries to free the `pp' pointer.
This pointer was not dynamically allocated but does in fact point to an element of the port[] array member of the struct ahci_uc_priv. Remove the erroneous call to free() to fix this.

I think free() doesn't do much (harm) in U-Boot, but it's definitely not right here. I see one malloc() in this driver (for ataid[port]), for which I cannot find the corresponding free(), but this is a separate issue, and this patch here is fine.

Quoted 2 lines
Fixes 4782ac80b02f ("Add AHCI support to u-boot")

Cheers,
Andre

Quoted 18 lines
Cc Tom Rini <[email protected]>
Cc Jason Jin <[email protected]>
---
 drivers/ata/ahci.c | 1 -
 1 file changed, 1 deletion(-)
drivers/ata/ahci.c +0 -1
index 8058d5ff1c3..e593e228685 100644
@@ -463,7 +463,6 @@ static int ahci_port_start(struct ahci_uc_priv *uc_priv, u8 port)
 
 	mem = memalign(2048, AHCI_PORT_PRIV_DMA_SZ);
 	if (!mem) {
-		free(pp);
 		printf("%s: No mem for table!\n", __func__);
 		return -ENOMEM;
 	}
#2 lore raw
In reply to Vincent Stehlé
Quoted 8 lines · Vincent Stehlé

In the case of a memory allocation error, the ahci_port_start() function tries to free the `pp' pointer.
This pointer was not dynamically allocated but does in fact point to an element of the port[] array member of the struct ahci_uc_priv. Remove the erroneous call to free() to fix this.

[...]

Applied to u-boot/master, thanks!

[1/1] ata: ahci: remove bad free

      commit: a345f44a60f57a2741cda9315312d3df28bc22f0
Signature · 1 line
Tom