git: 8b8e56dd5bc7 - main - Check if iommu ctx is valid before passing it to functions.

From: Ruslan Bukin <br_at_FreeBSD.org>
Date: Sat, 07 May 2022 09:29:19 UTC
The branch main has been updated by br:

URL: https://cgit.FreeBSD.org/src/commit/?id=8b8e56dd5bc781b7d1c7185cd267b0b16a637aa2

commit 8b8e56dd5bc781b7d1c7185cd267b0b16a637aa2
Author:     Ruslan Bukin <br@FreeBSD.org>
AuthorDate: 2022-05-07 09:27:17 +0000
Commit:     Ruslan Bukin <br@FreeBSD.org>
CommitDate: 2022-05-07 09:27:17 +0000

    Check if iommu ctx is valid before passing it to functions.
    
    Differential Revision:  https://reviews.freebsd.org/D35130
    Sponsored by:   UKRI
---
 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 7b06a44f35b3..a77be66bdd7f 100644
--- a/sys/arm64/arm64/gicv3_its.c
+++ b/sys/arm64/arm64/gicv3_its.c
@@ -1481,6 +1481,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);
@@ -1494,6 +1496,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