xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: elena.ufimtseva@oracle.com
To: xen-devel@lists.xen.org
Cc: Elena Ufimtseva <elena.ufimtseva@oracle.com>,
	kevin.tian@intel.com, tim@xen.org, jbeulich@suse.com,
	yang.z.zhang@intel.com, boris.ostrovsky@oracle.com
Subject: [PATCH v2] dmar: device scope mem leak fix
Date: Fri, 29 May 2015 17:34:57 -0400	[thread overview]
Message-ID: <1432935297-5610-1-git-send-email-elena.ufimtseva@oracle.com> (raw)

From: Elena Ufimtseva <elena.ufimtseva@oracle.com>

Release memory allocated for scope.devices when disabling
dmar units. Also set device count after memory allocation when
device scope parsing.

Changes in v2:
 - release memory for devices scope on error paths in acpi_parse_one_drhd
 and acpi_parse_one_atsr and set the count to zero;

Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
---
 xen/drivers/passthrough/vtd/dmar.c | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/xen/drivers/passthrough/vtd/dmar.c b/xen/drivers/passthrough/vtd/dmar.c
index 2b07be9..0985150 100644
--- a/xen/drivers/passthrough/vtd/dmar.c
+++ b/xen/drivers/passthrough/vtd/dmar.c
@@ -90,16 +90,19 @@ static void __init disable_all_dmar_units(void)
     list_for_each_entry_safe ( drhd, _drhd, &acpi_drhd_units, list )
     {
         list_del(&drhd->list);
+        xfree(drhd->scope.devices);
         xfree(drhd);
     }
     list_for_each_entry_safe ( rmrr, _rmrr, &acpi_rmrr_units, list )
     {
         list_del(&rmrr->list);
+        xfree(rmrr->scope.devices);
         xfree(rmrr);
     }
     list_for_each_entry_safe ( atsr, _atsr, &acpi_atsr_units, list )
     {
         list_del(&atsr->list);
+        xfree(atsr->scope.devices);
         xfree(atsr);
     }
 }
@@ -318,13 +321,13 @@ static int __init acpi_parse_dev_scope(
     if ( (cnt = scope_device_count(start, end)) < 0 )
         return cnt;
 
-    scope->devices_cnt = cnt;
     if ( cnt > 0 )
     {
         scope->devices = xzalloc_array(u16, cnt);
         if ( !scope->devices )
             return -ENOMEM;
     }
+    scope->devices_cnt = cnt;
 
     while ( start < end )
     {
@@ -427,7 +430,10 @@ static int __init acpi_parse_dev_scope(
 
  out:
     if ( ret )
+    {
+        scope->devices_cnt = 0;
         xfree(scope->devices);
+    }
 
     return ret;
 }
@@ -478,8 +484,6 @@ acpi_parse_one_drhd(struct acpi_dmar_header *header)
 
     dev_scope_start = (void *)(drhd + 1);
     dev_scope_end = ((void *)drhd) + header->length;
-    ret = acpi_parse_dev_scope(dev_scope_start, dev_scope_end,
-                               &dmaru->scope, DMAR_TYPE, drhd->segment);
 
     if ( dmaru->include_all )
     {
@@ -496,6 +500,8 @@ acpi_parse_one_drhd(struct acpi_dmar_header *header)
             include_all = 1;
     }
 
+    ret = acpi_parse_dev_scope(dev_scope_start, dev_scope_end,
+                               &dmaru->scope, DMAR_TYPE, drhd->segment);
     if ( ret )
         goto out;
     else if ( force_iommu || dmaru->include_all )
@@ -554,6 +560,8 @@ acpi_parse_one_drhd(struct acpi_dmar_header *header)
                     "really want VT-d\n");
                 ret = -EINVAL;
             }
+            dmaru->scope.devices_cnt = 0;
+            xfree(dmaru->scope.devices);
         }
         else
             acpi_register_drhd_unit(dmaru);
@@ -727,7 +735,11 @@ acpi_parse_one_atsr(struct acpi_dmar_header *header)
     }
 
     if ( ret )
+    {
+        atsru->scope.devices_cnt = 0;
+        xfree(atsru->scope.devices);
         xfree(atsru);
+    }
     else
         acpi_register_atsr_unit(atsru);
     return ret;
-- 
2.1.3

             reply	other threads:[~2015-05-29 21:34 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-29 21:34 elena.ufimtseva [this message]
2015-06-01  4:43 ` [PATCH v2] dmar: device scope mem leak fix Tian, Kevin
2015-06-01  4:47 ` Tian, Kevin
2015-06-01  8:45   ` Jan Beulich
2015-06-01 15:19     ` Elena Ufimtseva

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=1432935297-5610-1-git-send-email-elena.ufimtseva@oracle.com \
    --to=elena.ufimtseva@oracle.com \
    --cc=boris.ostrovsky@oracle.com \
    --cc=jbeulich@suse.com \
    --cc=kevin.tian@intel.com \
    --cc=tim@xen.org \
    --cc=xen-devel@lists.xen.org \
    --cc=yang.z.zhang@intel.com \
    /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).