From: Kun(llfl) Date: Thu, 9 May 2024 00:42:20 +0000 (+0800) Subject: iommu/amd: Fix sysfs leak in iommu init X-Git-Tag: v6.10-rc3~22^2~5 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a295ec52c8624883885396fde7b4df1a179627c3;p=thirdparty%2Fkernel%2Flinux.git iommu/amd: Fix sysfs leak in iommu init During the iommu initialization, iommu_init_pci() adds sysfs nodes. However, these nodes aren't remove in free_iommu_resources() subsequently. Fixes: 39ab9555c241 ("iommu: Add sysfs bindings for struct iommu_device") Signed-off-by: Kun(llfl) Reviewed-by: Suravee Suthikulpanit Link: https://lore.kernel.org/r/c8e0d11c6ab1ee48299c288009cf9c5dae07b42d.1715215003.git.llfl@linux.alibaba.com Signed-off-by: Joerg Roedel --- diff --git a/drivers/iommu/amd/init.c b/drivers/iommu/amd/init.c index a18e74878f68a..27e2937270950 100644 --- a/drivers/iommu/amd/init.c +++ b/drivers/iommu/amd/init.c @@ -1626,8 +1626,17 @@ static void __init free_pci_segments(void) } } +static void __init free_sysfs(struct amd_iommu *iommu) +{ + if (iommu->iommu.dev) { + iommu_device_unregister(&iommu->iommu); + iommu_device_sysfs_remove(&iommu->iommu); + } +} + static void __init free_iommu_one(struct amd_iommu *iommu) { + free_sysfs(iommu); free_cwwb_sem(iommu); free_command_buffer(iommu); free_event_buffer(iommu);