From eb852346acd2a0c781a8544495d1d3464ffacb56 Mon Sep 17 00:00:00 2001 From: HikariKnight <2557889+HikariKnight@users.noreply.github.com> Date: Tue, 7 Mar 2023 00:11:52 +0100 Subject: [PATCH] Fatal if requested IOMMU group does not exist --- main.go | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/main.go b/main.go index 97b92e9..4aad909 100644 --- a/main.go +++ b/main.go @@ -81,15 +81,21 @@ func printIOMMUgroup(groups []int) { if len(groups) > 0 { // Get all IOMMU devices alldevs := iommu.NewIOMMU() + // For each IOMMU group given we will print the devices in each group for _, group := range groups { - // For each device in specified IOMMU group - for _, device := range alldevs.Groups[group].Devices { - // Generate output line - line := iommu.GenDeviceLine(group, device) - - // Print the device info - fmt.Print(line) + // Check if the IOMMU Group exists + if _, iommu_num := alldevs.Groups[group]; !iommu_num { + iommu.ErrorCheck(fmt.Errorf("IOMMU Group %v does not exist", group)) + } else { + // For each device in specified IOMMU group + for _, device := range alldevs.Groups[group].Devices { + // Generate output line + line := iommu.GenDeviceLine(group, device) + + // Print the device info + fmt.Print(line) + } } } }