Commit ad0834de authored by Eric Auger's avatar Eric Auger Committed by Joerg Roedel

iommu: Fix a leak in iommu_insert_resv_region

In case we expand an existing region, we unlink
this latter and insert the larger one. In
that case we should free the original region after
the insertion. Also we can immediately return.

Fixes: 6c65fb31 ("iommu: iommu_get_group_resv_regions")
Signed-off-by: default avatarEric Auger <eric.auger@redhat.com>
Signed-off-by: default avatarJoerg Roedel <jroedel@suse.de>
parent 2de03c11
...@@ -237,18 +237,21 @@ static int iommu_insert_resv_region(struct iommu_resv_region *new, ...@@ -237,18 +237,21 @@ static int iommu_insert_resv_region(struct iommu_resv_region *new,
pos = pos->next; pos = pos->next;
} else if ((start >= a) && (end <= b)) { } else if ((start >= a) && (end <= b)) {
if (new->type == type) if (new->type == type)
goto done; return 0;
else else
pos = pos->next; pos = pos->next;
} else { } else {
if (new->type == type) { if (new->type == type) {
phys_addr_t new_start = min(a, start); phys_addr_t new_start = min(a, start);
phys_addr_t new_end = max(b, end); phys_addr_t new_end = max(b, end);
int ret;
list_del(&entry->list); list_del(&entry->list);
entry->start = new_start; entry->start = new_start;
entry->length = new_end - new_start + 1; entry->length = new_end - new_start + 1;
iommu_insert_resv_region(entry, regions); ret = iommu_insert_resv_region(entry, regions);
kfree(entry);
return ret;
} else { } else {
pos = pos->next; pos = pos->next;
} }
...@@ -261,7 +264,6 @@ static int iommu_insert_resv_region(struct iommu_resv_region *new, ...@@ -261,7 +264,6 @@ static int iommu_insert_resv_region(struct iommu_resv_region *new,
return -ENOMEM; return -ENOMEM;
list_add_tail(&region->list, pos); list_add_tail(&region->list, pos);
done:
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment