diff options
author | Jiang Liu <jiang.liu@linux.intel.com> | 2014-01-06 01:18:09 -0500 |
---|---|---|
committer | Joerg Roedel <joro@8bytes.org> | 2014-01-09 06:42:35 -0500 |
commit | ada4d4b2a32e9f63d4dcb9f69578473408f4622c (patch) | |
tree | 7f50f2c380f4e46bfd4fb3317a5e4f17b35c3ab2 /drivers/iommu/dmar.c | |
parent | 360eb3c5687e2df23e29e97878238765bfe6a756 (diff) |
iommu/vt-d: fix PCI device reference leakage on error recovery path
Function dmar_parse_dev_scope() should release the PCI device reference
count gained in function dmar_parse_one_dev_scope() on error recovery,
otherwise it will cause PCI device object leakage.
This patch also introduces dmar_free_dev_scope(), which will be used
to support DMAR device hotplug.
Reviewed-by: Yijing Wang <wangyijing@huawei.com>
Signed-off-by: Jiang Liu <jiang.liu@linux.intel.com>
Signed-off-by: Joerg Roedel <joro@8bytes.org>
Diffstat (limited to 'drivers/iommu/dmar.c')
-rw-r--r-- | drivers/iommu/dmar.c | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/drivers/iommu/dmar.c b/drivers/iommu/dmar.c index fb35d1bd19e1..28d93b68ff02 100644 --- a/drivers/iommu/dmar.c +++ b/drivers/iommu/dmar.c | |||
@@ -100,7 +100,6 @@ static int __init dmar_parse_one_dev_scope(struct acpi_dmar_device_scope *scope, | |||
100 | if (!pdev) { | 100 | if (!pdev) { |
101 | pr_warn("Device scope device [%04x:%02x:%02x.%02x] not found\n", | 101 | pr_warn("Device scope device [%04x:%02x:%02x.%02x] not found\n", |
102 | segment, scope->bus, path->device, path->function); | 102 | segment, scope->bus, path->device, path->function); |
103 | *dev = NULL; | ||
104 | return 0; | 103 | return 0; |
105 | } | 104 | } |
106 | if ((scope->entry_type == ACPI_DMAR_SCOPE_TYPE_ENDPOINT && \ | 105 | if ((scope->entry_type == ACPI_DMAR_SCOPE_TYPE_ENDPOINT && \ |
@@ -151,7 +150,7 @@ int __init dmar_parse_dev_scope(void *start, void *end, int *cnt, | |||
151 | ret = dmar_parse_one_dev_scope(scope, | 150 | ret = dmar_parse_one_dev_scope(scope, |
152 | &(*devices)[index], segment); | 151 | &(*devices)[index], segment); |
153 | if (ret) { | 152 | if (ret) { |
154 | kfree(*devices); | 153 | dmar_free_dev_scope(devices, cnt); |
155 | return ret; | 154 | return ret; |
156 | } | 155 | } |
157 | index ++; | 156 | index ++; |
@@ -162,6 +161,17 @@ int __init dmar_parse_dev_scope(void *start, void *end, int *cnt, | |||
162 | return 0; | 161 | return 0; |
163 | } | 162 | } |
164 | 163 | ||
164 | void dmar_free_dev_scope(struct pci_dev ***devices, int *cnt) | ||
165 | { | ||
166 | if (*devices && *cnt) { | ||
167 | while (--*cnt >= 0) | ||
168 | pci_dev_put((*devices)[*cnt]); | ||
169 | kfree(*devices); | ||
170 | *devices = NULL; | ||
171 | *cnt = 0; | ||
172 | } | ||
173 | } | ||
174 | |||
165 | /** | 175 | /** |
166 | * dmar_parse_one_drhd - parses exactly one DMA remapping hardware definition | 176 | * dmar_parse_one_drhd - parses exactly one DMA remapping hardware definition |
167 | * structure which uniquely represent one DMA remapping hardware unit | 177 | * structure which uniquely represent one DMA remapping hardware unit |