From: Zheng Qixing <zhengqixing@huawei.com>
To: Zheng Qixing <zhengqixing@huaweicloud.com>, <dlemoal@kernel.org>
Cc: <linux-ide@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<yukuai3@huawei.com>, <yi.zhang@huawei.com>,
<yangerkun@huawei.com>
Subject: Re: [PATCH] ata:Fix memory leak for error path in ata_host_alloc()
Date: Thu, 22 Aug 2024 11:29:19 +0800 [thread overview]
Message-ID: <af7a5219-76e7-4d1e-b05f-9674919abc62@huawei.com> (raw)
In-Reply-To: <20240822031742.2721254-1-zhengqixing@huaweicloud.com>
在 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
prev parent reply other threads:[~2024-08-22 3:29 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-22 3:17 Zheng Qixing
2024-08-22 3:29 ` Zheng Qixing [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=af7a5219-76e7-4d1e-b05f-9674919abc62@huawei.com \
--to=zhengqixing@huawei.com \
--cc=dlemoal@kernel.org \
--cc=linux-ide@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=yangerkun@huawei.com \
--cc=yi.zhang@huawei.com \
--cc=yukuai3@huawei.com \
--cc=zhengqixing@huaweicloud.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®