git: 0c0bfa0f6f2f - main - Fix ofw_bus_iommu_map() since there is no limit on amount of maps described in "iommu-map" DTS property.
Date: Fri, 06 May 2022 17:10:34 UTC
The branch main has been updated by br:
URL: https://cgit.FreeBSD.org/src/commit/?id=0c0bfa0f6f2f3415f139aa65019f43f498883a89
commit 0c0bfa0f6f2f3415f139aa65019f43f498883a89
Author: Ruslan Bukin <br@FreeBSD.org>
AuthorDate: 2022-05-06 17:03:52 +0000
Commit: Ruslan Bukin <br@FreeBSD.org>
CommitDate: 2022-05-06 17:09:42 +0000
Fix ofw_bus_iommu_map() since there is no limit on amount of maps
described in "iommu-map" DTS property.
Pointed out by: rpokala
Sponsored by: UKRI
---
sys/dev/ofw/ofw_bus_subr.c | 14 ++++++--------
1 file changed, 6 insertions(+), 8 deletions(-)
diff --git a/sys/dev/ofw/ofw_bus_subr.c b/sys/dev/ofw/ofw_bus_subr.c
index 408d554b3c7f..404bed3c73fa 100644
--- a/sys/dev/ofw/ofw_bus_subr.c
+++ b/sys/dev/ofw/ofw_bus_subr.c
@@ -495,19 +495,15 @@ int
ofw_bus_iommu_map(phandle_t node, uint16_t pci_rid, phandle_t *iommu_parent,
uint32_t *iommu_rid)
{
- pcell_t mask, iommu_base, rid_base, rid_length;
- uint32_t masked_rid;
- pcell_t map[4];
+ pcell_t *map, mask, iommu_base, rid_base, rid_length;
ssize_t len;
+ uint32_t masked_rid;
int err, i;
- len = OF_getproplen(node, "iommu-map");
+ len = OF_getencprop_alloc_multi(node, "iommu-map", sizeof(*map),
+ (void **)&map);
if (len <= 0)
return (ENOENT);
- if (len > sizeof(map))
- return (ENOMEM);
-
- len = OF_getencprop(node, "iommu-map", map, 16);
err = ENOENT;
mask = 0xffffffff;
@@ -532,6 +528,8 @@ ofw_bus_iommu_map(phandle_t node, uint16_t pci_rid, phandle_t *iommu_parent,
break;
}
+ free(map, M_OFWPROP);
+
return (err);
}