git: 4ae24f166c81 - stable/13 - Check if iommu ctx is valid before passing it to functions.

From: Doug Moore <dougm_at_FreeBSD.org>
Date: Wed, 06 Jul 2022 17:05:00 UTC
The branch stable/13 has been updated by dougm:

URL: https://cgit.FreeBSD.org/src/commit/?id=4ae24f166c81c98ce2915d1c7a60bf7ccb89b6fa

commit 4ae24f166c81c98ce2915d1c7a60bf7ccb89b6fa
Author:     Ruslan Bukin <br@FreeBSD.org>
AuthorDate: 2022-05-07 09:27:17 +0000
Commit:     Doug Moore <dougm@FreeBSD.org>
CommitDate: 2022-07-06 16:41:03 +0000

    Check if iommu ctx is valid before passing it to functions.
    
    Differential Revision:  https://reviews.freebsd.org/D35130
    Sponsored by:   UKRI
    
    (cherry picked from commit 8b8e56dd5bc781b7d1c7185cd267b0b16a637aa2)
---
 sys/arm64/arm64/gicv3_its.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/sys/arm64/arm64/gicv3_its.c b/sys/arm64/arm64/gicv3_its.c
index 5f78a754b57c..35a5642a95dc 100644
--- a/sys/arm64/arm64/gicv3_its.c
+++ b/sys/arm64/arm64/gicv3_its.c
@@ -1455,6 +1455,8 @@ gicv3_iommu_init(device_t dev, device_t child, struct iommu_domain **domain)
 
 	sc = device_get_softc(dev);
 	ctx = iommu_get_dev_ctx(child);
+	if (ctx == NULL)
+		return (ENXIO);
 	error = iommu_map_msi(ctx, PAGE_SIZE, GITS_TRANSLATER,
 	    IOMMU_MAP_ENTRY_WRITE, IOMMU_MF_CANWAIT, &sc->ma);
 	*domain = iommu_get_ctx_domain(ctx);
@@ -1468,6 +1470,9 @@ gicv3_iommu_deinit(device_t dev, device_t child)
 	struct iommu_ctx *ctx;
 
 	ctx = iommu_get_dev_ctx(child);
+	if (ctx == NULL)
+		return;
+
 	iommu_unmap_msi(ctx);
 }
 #endif