drivers/ata/libata-core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
From: Zheng Qixing <zhengqixing@huawei.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@huawei.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
在 2024/8/22 11:17, Zheng Qixing 写道:
> From: Zheng Qixing <zhengqixing@huawei.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@huawei.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;
Sorry, this patch is wrong, i will send a new version.
Zheng Qixing
© 2016 - 2026 Red Hat, Inc.