Skip to contentSkip to conversation

x86, amd_ucode: Fix coverity issues found in cpu_request_microcode()

PATCH Superseded Aravind Gopalakrishnan 2 participants 3 messages Jul 30, 2014

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 x86, amd_ucode: Fix coverity issues found in cpu_request_microcode()

This patch fixes issues found in CID 1229147(dead code) and CID 1229148: possible resource leak of mc_amd due to goto out statements.

---
 xen/arch/x86/microcode_amd.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
xen/arch/x86/microcode_amd.c +7 -6
index 14728a2..a2bdd20 100644
@@ -384,9 +384,12 @@ static int cpu_request_microcode(int cpu, const void *buf, size_t bufsize)
     while ( offset < bufsize )
     {
         error = install_equiv_cpu_table(mc_amd, buf, &offset);
+        if ( error ) {
+            printk(KERN_ERR "microcode: installing equivalent cpu table failed\n");
+            break;
+        }
 
-        if ( !error &&
-             find_equiv_cpu_id(mc_amd->equiv_cpu_table, current_cpu_id,
+        if ( find_equiv_cpu_id(mc_amd->equiv_cpu_table, current_cpu_id,
                                &equiv_cpu_id) )
                 break;
 
@@ -398,7 +401,7 @@ static int cpu_request_microcode(int cpu, const void *buf, size_t bufsize)
         {
             printk(KERN_ERR "microcode: Microcode buffer overrun\n");
             error = -EINVAL;
-            goto out;
+            break;
         }
 
         error = container_fast_forward(buf, bufsize - offset, &offset);
@@ -407,15 +410,13 @@ static int cpu_request_microcode(int cpu, const void *buf, size_t bufsize)
             printk(KERN_ERR "microcode: CPU%d incorrect or corrupt container file\n"
                    "microcode: Failed to update patch level. "
                    "Current lvl:%#x\n", cpu, uci->cpu_sig.rev);
-            goto out;
+            break;
         }
     }
 
     if ( error )
     {
         xfree(mc_amd);
-        printk(KERN_ERR "microcode: installing equivalent cpu table failed\n");
-        error = -EINVAL;
         goto out;
     }
 
Signature · 1 line
2.0.3
#1 lore raw
Quoted 15 lines · Aravind Gopalakrishnan

This patch fixes issues found in CID 1229147(dead code) and CID 1229148: possible resource leak of mc_amd due to goto out statements.

---
  xen/arch/x86/microcode_amd.c | 13 +++++++------
  1 file changed, 7 insertions(+), 6 deletions(-)
xen/arch/x86/microcode_amd.c +0 -0
index 14728a2..a2bdd20 100644

xen/arch/x86/microcode_amd.c static int cpu_request_microcode(int cpu, const void *buf, size_t bufsize) · line 387

Quoted 4 lines
xen/arch/x86/microcode_amd.c +1 -0
@@ -384,9 +384,12 @@ static int cpu_request_microcode(int cpu, const void *buf, size_t bufsize)
      while ( offset < bufsize )
      {
          error = install_equiv_cpu_table(mc_amd, buf, &offset);
+        if ( error ) {

Darn. I just noticed this. Will modify this.
I'll wait to see if there are more suggestions before I send a V2 for this.

- Aravind.

#2 lore raw
In reply to Aravind Gopalakrishnan
Quoted 6 lines · Aravind Gopalakrishnan

This patch fixes issues found in CID 1229147(dead code) and CID 1229148: possible resource leak of mc_amd due to goto out statements.

Coverity-IDs: 1229147, 1229148

We tend to annotate IDs like this in commits.

With your noticed adjustment, Reviewed-by: Andrew Cooper <[email protected]>

Quoted 49 lines
---
 xen/arch/x86/microcode_amd.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
xen/arch/x86/microcode_amd.c +7 -6
index 14728a2..a2bdd20 100644
@@ -384,9 +384,12 @@ static int cpu_request_microcode(int cpu, const void *buf, size_t bufsize)
     while ( offset < bufsize )
     {
         error = install_equiv_cpu_table(mc_amd, buf, &offset);
+        if ( error ) {
+            printk(KERN_ERR "microcode: installing equivalent cpu table failed\n");
+            break;
+        }
 
-        if ( !error &&
-             find_equiv_cpu_id(mc_amd->equiv_cpu_table, current_cpu_id,
+        if ( find_equiv_cpu_id(mc_amd->equiv_cpu_table, current_cpu_id,
                                &equiv_cpu_id) )
                 break;
 
@@ -398,7 +401,7 @@ static int cpu_request_microcode(int cpu, const void *buf, size_t bufsize)
         {
             printk(KERN_ERR "microcode: Microcode buffer overrun\n");
             error = -EINVAL;
-            goto out;
+            break;
         }
 
         error = container_fast_forward(buf, bufsize - offset, &offset);
@@ -407,15 +410,13 @@ static int cpu_request_microcode(int cpu, const void *buf, size_t bufsize)
             printk(KERN_ERR "microcode: CPU%d incorrect or corrupt container file\n"
                    "microcode: Failed to update patch level. "
                    "Current lvl:%#x\n", cpu, uci->cpu_sig.rev);
-            goto out;
+            break;
         }
     }
 
     if ( error )
     {
         xfree(mc_amd);
-        printk(KERN_ERR "microcode: installing equivalent cpu table failed\n");
-        error = -EINVAL;
         goto out;
     }