Skip to contentSkip to conversation

VT-d: Fix resource leaks on error paths

PATCH In review Igor Mammedov 2 participants 2 messages May 12, 2011 – May 13, 2011

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 VT-d: Fix resource leaks on error paths

On error exit from functions, maped pages should be unmapped and acquired locks released.

xen/drivers/passthrough/vtd/intremap.c +8 -2
diff -r 4b0692880dfa -r da93d9e43b3c xen/drivers/passthrough/vtd/intremap.c
@@ -210,7 +210,8 @@
     if ( iremap_entries )
         unmap_vtd_domain_page(iremap_entries);
 
-    ir_ctrl->iremap_num++;
+    if ( i < IREMAP_ENTRY_NR ) 
+	    ir_ctrl->iremap_num++;
     return i;
 }
 
@@ -246,6 +247,8 @@
         dprintk(XENLOG_ERR VTDPREFIX,
                 "%s: index (%d) get an empty entry!\n",
                 __func__, index);
+	unmap_vtd_domain_page(iremap_entries);
+	spin_unlock_irqrestore(&ir_ctrl->iremap_lock, flags);
         return -EFAULT;
     }
 
@@ -281,7 +284,8 @@
     if ( index < 0 )
     {
         index = alloc_remap_entry(iommu);
-        apic_pin_2_ir_idx[apic][ioapic_pin] = index;
+        if ( index < IREMAP_ENTRY_NR )
+            apic_pin_2_ir_idx[apic][ioapic_pin] = index;
     }
 
     if ( index > IREMAP_ENTRY_NR - 1 )
@@ -546,6 +550,8 @@
         dprintk(XENLOG_ERR VTDPREFIX,
                 "%s: index (%d) get an empty entry!\n",
                 __func__, index);
+	unmap_vtd_domain_page(iremap_entries);
+	spin_unlock_irqrestore(&ir_ctrl->iremap_lock, flags);
         return -EFAULT;
     }
#1 lore raw

Looks good to me. ACK!

-----Original Message-----
From: Igor Mammedov [mailto:[email protected]]
Sent: Thursday, May 12, 2011 1:30 AM
To: [email protected]
Cc: Kay, Allen M; [email protected]
Subject: [Xen HV PATCH] VT-d: Fix resource leaks on error paths

On error exit from functions, maped pages should be unmapped and acquired locks released.

xen/drivers/passthrough/vtd/intremap.c +8 -2
diff -r 4b0692880dfa -r da93d9e43b3c xen/drivers/passthrough/vtd/intremap.c
@@ -210,7 +210,8 @@
     if ( iremap_entries )
         unmap_vtd_domain_page(iremap_entries);
 
-    ir_ctrl->iremap_num++;
+    if ( i < IREMAP_ENTRY_NR ) 
+	    ir_ctrl->iremap_num++;
     return i;
 }
 
@@ -246,6 +247,8 @@
         dprintk(XENLOG_ERR VTDPREFIX,
                 "%s: index (%d) get an empty entry!\n",
                 __func__, index);
+	unmap_vtd_domain_page(iremap_entries);
+	spin_unlock_irqrestore(&ir_ctrl->iremap_lock, flags);
         return -EFAULT;
     }
 
@@ -281,7 +284,8 @@
     if ( index < 0 )
     {
         index = alloc_remap_entry(iommu);
-        apic_pin_2_ir_idx[apic][ioapic_pin] = index;
+        if ( index < IREMAP_ENTRY_NR )
+            apic_pin_2_ir_idx[apic][ioapic_pin] = index;
     }
 
     if ( index > IREMAP_ENTRY_NR - 1 )
@@ -546,6 +550,8 @@
         dprintk(XENLOG_ERR VTDPREFIX,
                 "%s: index (%d) get an empty entry!\n",
                 __func__, index);
+	unmap_vtd_domain_page(iremap_entries);
+	spin_unlock_irqrestore(&ir_ctrl->iremap_lock, flags);
         return -EFAULT;
     }