xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: "Jan Beulich" <JBeulich@suse.com>
To: xen-devel <xen-devel@lists.xenproject.org>
Cc: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>
Subject: [PATCH] AMD IOMMU: correctly propagate errors from amd_iommu_init()
Date: Tue, 14 Jun 2016 03:03:09 -0600	[thread overview]
Message-ID: <575FE46D02000078000F4A8F@prv-mh.provo.novell.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 2541 bytes --]

... instead of using -ENODEV for any kind of error. It in particular
addresses Coverity ID 1362694 (introduced by commit eb48587210 ["AMD
IOMMU: introduce support for IVHD block type 11h"]).

Coverity ID: 1362694

Signed-off-by: Jan Beulich <jbeulich@suse.com>

--- a/xen/drivers/passthrough/amd/iommu_init.c
+++ b/xen/drivers/passthrough/amd/iommu_init.c
@@ -1226,6 +1226,7 @@ static bool_t __init amd_sp5100_erratum2
 int __init amd_iommu_init(void)
 {
     struct amd_iommu *iommu;
+    int rc = -ENODEV;
 
     BUG_ON( !iommu_found() );
 
@@ -1237,28 +1238,39 @@ int __init amd_iommu_init(void)
     if ( unlikely(acpi_gbl_FADT.boot_flags & ACPI_FADT_NO_MSI) )
         goto error_out;
 
-    ivhd_type = amd_iommu_get_supported_ivhd_type();
-    if ( ivhd_type < 0 )
+    rc = amd_iommu_get_supported_ivhd_type();
+    if ( rc < 0 )
         goto error_out;
+    ivhd_type = rc;
 
-    ivrs_bdf_entries = amd_iommu_get_ivrs_dev_entries();
-    if ( !ivrs_bdf_entries )
+    rc = amd_iommu_get_ivrs_dev_entries();
+    if ( !rc )
+        rc = -ENODEV;
+    if ( rc < 0 )
         goto error_out;
+    ivrs_bdf_entries = rc;
 
     radix_tree_init(&ivrs_maps);
     for_each_amd_iommu ( iommu )
-        if ( alloc_ivrs_mappings(iommu->seg) != 0 )
+    {
+        rc = alloc_ivrs_mappings(iommu->seg);
+        if ( rc )
             goto error_out;
+    }
 
-    if ( amd_iommu_update_ivrs_mapping_acpi() != 0 )
+    rc = amd_iommu_update_ivrs_mapping_acpi();
+    if ( rc )
         goto error_out;
 
     /* initialize io-apic interrupt remapping entries */
-    if ( iommu_intremap && amd_iommu_setup_ioapic_remapping() != 0 )
+    if ( iommu_intremap )
+        rc = amd_iommu_setup_ioapic_remapping();
+    if ( rc )
         goto error_out;
 
     /* allocate and initialize a global device table shared by all iommus */
-    if ( iterate_ivrs_mappings(amd_iommu_setup_device_table) != 0 )
+    rc = iterate_ivrs_mappings(amd_iommu_setup_device_table);
+    if ( rc )
         goto error_out;
 
     /*
@@ -1271,14 +1283,17 @@ int __init amd_iommu_init(void)
 
     /* per iommu initialization  */
     for_each_amd_iommu ( iommu )
-        if ( amd_iommu_init_one(iommu) != 0 )
+    {
+        rc = amd_iommu_init_one(iommu);
+        if ( rc )
             goto error_out;
+    }
 
     return 0;
 
 error_out:
     amd_iommu_init_cleanup();
-    return -ENODEV;
+    return rc;
 }
 
 static void disable_iommu(struct amd_iommu *iommu)




[-- Attachment #2: CID1362694.patch --]
[-- Type: text/plain, Size: 2598 bytes --]

AMD IOMMU: correctly propagate errors from amd_iommu_init()

... instead of using -ENODEV for any kind of error. It in particular
addresses Coverity ID 1362694 (introduced by commit eb48587210 ["AMD
IOMMU: introduce support for IVHD block type 11h"]).

Coverity ID: 1362694

Signed-off-by: Jan Beulich <jbeulich@suse.com>

--- a/xen/drivers/passthrough/amd/iommu_init.c
+++ b/xen/drivers/passthrough/amd/iommu_init.c
@@ -1226,6 +1226,7 @@ static bool_t __init amd_sp5100_erratum2
 int __init amd_iommu_init(void)
 {
     struct amd_iommu *iommu;
+    int rc = -ENODEV;
 
     BUG_ON( !iommu_found() );
 
@@ -1237,28 +1238,39 @@ int __init amd_iommu_init(void)
     if ( unlikely(acpi_gbl_FADT.boot_flags & ACPI_FADT_NO_MSI) )
         goto error_out;
 
-    ivhd_type = amd_iommu_get_supported_ivhd_type();
-    if ( ivhd_type < 0 )
+    rc = amd_iommu_get_supported_ivhd_type();
+    if ( rc < 0 )
         goto error_out;
+    ivhd_type = rc;
 
-    ivrs_bdf_entries = amd_iommu_get_ivrs_dev_entries();
-    if ( !ivrs_bdf_entries )
+    rc = amd_iommu_get_ivrs_dev_entries();
+    if ( !rc )
+        rc = -ENODEV;
+    if ( rc < 0 )
         goto error_out;
+    ivrs_bdf_entries = rc;
 
     radix_tree_init(&ivrs_maps);
     for_each_amd_iommu ( iommu )
-        if ( alloc_ivrs_mappings(iommu->seg) != 0 )
+    {
+        rc = alloc_ivrs_mappings(iommu->seg);
+        if ( rc )
             goto error_out;
+    }
 
-    if ( amd_iommu_update_ivrs_mapping_acpi() != 0 )
+    rc = amd_iommu_update_ivrs_mapping_acpi();
+    if ( rc )
         goto error_out;
 
     /* initialize io-apic interrupt remapping entries */
-    if ( iommu_intremap && amd_iommu_setup_ioapic_remapping() != 0 )
+    if ( iommu_intremap )
+        rc = amd_iommu_setup_ioapic_remapping();
+    if ( rc )
         goto error_out;
 
     /* allocate and initialize a global device table shared by all iommus */
-    if ( iterate_ivrs_mappings(amd_iommu_setup_device_table) != 0 )
+    rc = iterate_ivrs_mappings(amd_iommu_setup_device_table);
+    if ( rc )
         goto error_out;
 
     /*
@@ -1271,14 +1283,17 @@ int __init amd_iommu_init(void)
 
     /* per iommu initialization  */
     for_each_amd_iommu ( iommu )
-        if ( amd_iommu_init_one(iommu) != 0 )
+    {
+        rc = amd_iommu_init_one(iommu);
+        if ( rc )
             goto error_out;
+    }
 
     return 0;
 
 error_out:
     amd_iommu_init_cleanup();
-    return -ENODEV;
+    return rc;
 }
 
 static void disable_iommu(struct amd_iommu *iommu)

[-- Attachment #3: Type: text/plain, Size: 126 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

             reply	other threads:[~2016-06-14  9:03 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-14  9:03 Jan Beulich [this message]
2016-06-14  9:09 ` [PATCH] AMD IOMMU: correctly propagate errors from amd_iommu_init() Andrew Cooper
2016-06-15 15:25   ` Suravee Suthikulanit
2016-06-16  2:03 ` Xu, Quan
2016-06-16  8:28   ` Jan Beulich
2016-06-16  8:57     ` Xu, Quan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=575FE46D02000078000F4A8F@prv-mh.provo.novell.com \
    --to=jbeulich@suse.com \
    --cc=suravee.suthikulpanit@amd.com \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).