Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 15 Jan 2026 14:19:00 +0000
From:      Mark Johnston <markj@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: 6740cccb1eff - main - arm64/iommu: Fix a resource leak in smmu_domain_alloc()
Message-ID:  <6968f754.f1f1.6a01e806@gitrepo.freebsd.org>

index | next in thread | raw e-mail

The branch main has been updated by markj:

URL: https://cgit.FreeBSD.org/src/commit/?id=6740cccb1eff2a0e1e6d451fa9676a21736937d2

commit 6740cccb1eff2a0e1e6d451fa9676a21736937d2
Author:     Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2026-01-15 14:04:19 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2026-01-15 14:04:19 +0000

    arm64/iommu: Fix a resource leak in smmu_domain_alloc()
    
    We should free the allocated ASID if smmu_init_cd() fails.
    
    Move the allocation of "domain" to simplify the first error path.
    
    Reported by:    Kevin Day <kevin@your.org>
    Reviewed by:    br
    MFC after:      1 week
    Differential Revision:  https://reviews.freebsd.org/D54676
---
 sys/arm64/iommu/smmu.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/sys/arm64/iommu/smmu.c b/sys/arm64/iommu/smmu.c
index ec8e04ce117b..a84ef4ae347e 100644
--- a/sys/arm64/iommu/smmu.c
+++ b/sys/arm64/iommu/smmu.c
@@ -1698,22 +1698,21 @@ smmu_domain_alloc(device_t dev, struct iommu_unit *iommu)
 
 	unit = (struct smmu_unit *)iommu;
 
-	domain = malloc(sizeof(*domain), M_SMMU, M_WAITOK | M_ZERO);
-
 	error = smmu_asid_alloc(sc, &new_asid);
 	if (error) {
-		free(domain, M_SMMU);
 		device_printf(sc->dev,
 		    "Could not allocate ASID for a new domain.\n");
 		return (NULL);
 	}
 
+	domain = malloc(sizeof(*domain), M_SMMU, M_WAITOK | M_ZERO);
 	domain->asid = (uint16_t)new_asid;
 
 	smmu_pmap_pinit(&domain->p);
 
 	error = smmu_init_cd(sc, domain);
 	if (error) {
+		smmu_asid_free(sc, domain->asid);
 		free(domain, M_SMMU);
 		device_printf(sc->dev, "Could not initialize CD\n");
 		return (NULL);


home | help

Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?6968f754.f1f1.6a01e806>