From: Robin Murphy <robin.murphy@arm.com>
To: "Kun(llfl)" <llfl@linux.alibaba.com>,
Joerg Roedel <joro@8bytes.org>,
Vasant Hegde <vasant.hegde@amd.com>
Cc: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>,
Will Deacon <will@kernel.org>,
iommu@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 1/1] iommu/amd: Fix memory leak in alloc_pci_segment()
Date: Thu, 25 Apr 2024 11:52:36 +0100 [thread overview]
Message-ID: <e3175546-5357-4946-97b1-7677b0596772@arm.com> (raw)
In-Reply-To: <a06d50c3a82214a82ccb88c22aa4e4a1d595b39c.1714040214.git.llfl@linux.alibaba.com>
On 25/04/2024 11:17 am, Kun(llfl) wrote:
> Fix the memory leak issue that occurs when resource allocation fails in
> alloc_pci_segment(). The dev_table, alias_table, and rlookup_table were
> introduced individually in three commits. But they all fail to release
> allocated resources when other allocations fail.
As far as I can tell the returned error should end up being handled in
state_next(), which *will* then clean these up again, at least in the
!irq_remapping_enabled path. If there's any cleanup missing from the
other path, then I think it should be fixed there, since it may well
represent more than just these particular allocations.
Thanks,
Robin.
> Fixes: 04230c119930 ("iommu/amd: Introduce per PCI segment device table")
> Fixes: 99fc4ac3d297 ("iommu/amd: Introduce per PCI segment alias_table"),
> Fixes: eda797a27795 ("iommu/amd: Introduce per PCI segment rlookup table").
> Reported-by: Xuchun Shang <xuchun.shang@linux.alibaba.com>
> Signed-off-by: Kun(llfl) <llfl@linux.alibaba.com>
> ---
> drivers/iommu/amd/init.c | 15 ++++++++++++---
> 1 file changed, 12 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/iommu/amd/init.c b/drivers/iommu/amd/init.c
> index ac6754a85f35..4ce567f39473 100644
> --- a/drivers/iommu/amd/init.c
> +++ b/drivers/iommu/amd/init.c
> @@ -1642,13 +1642,22 @@ static struct amd_iommu_pci_seg *__init alloc_pci_segment(u16 id,
> list_add_tail(&pci_seg->list, &amd_iommu_pci_seg_list);
>
> if (alloc_dev_table(pci_seg))
> - return NULL;
> + goto alloc_dev_fail;
> if (alloc_alias_table(pci_seg))
> - return NULL;
> + goto alloc_alias_fail;
> if (alloc_rlookup_table(pci_seg))
> - return NULL;
> + goto alloc_rlookup_fail;
>
> return pci_seg;
> +
> +alloc_rlookup_fail:
> + free_rlookup_table(pci_seg);
> +alloc_alias_fail:
> + free_alias_table(pci_seg);
> +alloc_dev_fail:
> + free_dev_table(pci_seg);
> + kfree(pci_seg);
> + return NULL;
> }
>
> static struct amd_iommu_pci_seg *__init get_pci_segment(u16 id,
prev parent reply other threads:[~2024-04-25 10:52 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-25 10:17 [PATCH v2 1/1] iommu/amd: Fix memory leak in alloc_pci_segment() Kun(llfl)
2024-04-25 10:52 ` Robin Murphy [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=e3175546-5357-4946-97b1-7677b0596772@arm.com \
--to=robin.murphy@arm.com \
--cc=iommu@lists.linux.dev \
--cc=joro@8bytes.org \
--cc=linux-kernel@vger.kernel.org \
--cc=llfl@linux.alibaba.com \
--cc=suravee.suthikulpanit@amd.com \
--cc=vasant.hegde@amd.com \
--cc=will@kernel.org \
/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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).