AMD/iommu_detect: don't leak iommu structure on error paths
authorAndrew Cooper <andrew.cooper3@citrix.com>
Tue, 7 Jan 2014 13:57:15 +0000 (14:57 +0100)
committerJan Beulich <jbeulich@suse.com>
Tue, 7 Jan 2014 13:57:15 +0000 (14:57 +0100)
Tweak the logic slightly to return the real errors from
get_iommu_{,msi_}capabilities(), which at the moment is no functional change.

Coverity-ID: 1146950
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Acked-by: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
xen/drivers/passthrough/amd/iommu_detect.c

index 6c10885b3f10409d162f31b952e471a65b526a76..be1b7610217b05182aacce7b2a1ee099db62138b 100644 (file)
@@ -145,11 +145,11 @@ int __init amd_iommu_detect_one_acpi(
     rt = get_iommu_capabilities(iommu->seg, bus, dev, func,
                                 iommu->cap_offset, iommu);
     if ( rt )
-        return -ENODEV;
+        goto out;
 
     rt = get_iommu_msi_capabilities(iommu->seg, bus, dev, func, iommu);
     if ( rt )
-        return -ENODEV;
+        goto out;
 
     rt = pci_ro_device(iommu->seg, bus, PCI_DEVFN(dev, func));
     if ( rt )
@@ -158,6 +158,11 @@ int __init amd_iommu_detect_one_acpi(
                iommu->seg, bus, dev, func, rt);
 
     list_add_tail(&iommu->list, &amd_iommu_head);
+    rt = 0;
 
-    return 0;
+ out:
+    if ( rt )
+        xfree(iommu);
+
+    return rt;
 }