[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20240822031742.2721254-1-zhengqixing@huaweicloud.com>
Date: Thu, 22 Aug 2024 11:17:42 +0800
From: Zheng Qixing <zhengqixing@...weicloud.com>
To: dlemoal@...nel.org
Cc: linux-ide@...r.kernel.org,
linux-kernel@...r.kernel.org,
yukuai3@...wei.com,
yi.zhang@...wei.com,
yangerkun@...wei.com,
zhengqixing@...wei.com
Subject: [PATCH] ata:Fix memory leak for error path in ata_host_alloc()
From: Zheng Qixing <zhengqixing@...wei.com>
In ata_host_alloc(), if ata_port_alloc(host) fails to allocate memory
for a port, the allocated 'host' structure is not freed before returning
from the function. This results in a potential memory leak.
This patch adds a kfree(host) before the error handling code is executed
to ensure that the 'host' structure is properly freed in case of an
allocation failure.
Signed-off-by: Zheng Qixing <zhengqixing@...wei.com>
---
drivers/ata/libata-core.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
index ee18c09c39b6..cb3ace759699 100644
--- a/drivers/ata/libata-core.c
+++ b/drivers/ata/libata-core.c
@@ -5610,9 +5610,10 @@ struct ata_host *ata_host_alloc(struct device *dev, int max_ports)
struct ata_port *ap;
ap = ata_port_alloc(host);
- if (!ap)
+ if (!ap) {
kfree(host);
goto err_out;
+ }
ap->port_no = i;
host->ports[i] = ap;
--
2.39.2
Powered by blists - more mailing lists