From: Elena Ufimtseva <elena.ufimts...@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.ufimts...@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 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel