Skip to content

Commit ad0834d

Browse files
eaugerjoergroedel
authored andcommitted
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: 6c65fb3 ("iommu: iommu_get_group_resv_regions") Signed-off-by: Eric Auger <[email protected]> Signed-off-by: Joerg Roedel <[email protected]>
1 parent 2de03c1 commit ad0834d

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

drivers/iommu/iommu.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,18 +237,21 @@ static int iommu_insert_resv_region(struct iommu_resv_region *new,
237237
pos = pos->next;
238238
} else if ((start >= a) && (end <= b)) {
239239
if (new->type == type)
240-
goto done;
240+
return 0;
241241
else
242242
pos = pos->next;
243243
} else {
244244
if (new->type == type) {
245245
phys_addr_t new_start = min(a, start);
246246
phys_addr_t new_end = max(b, end);
247+
int ret;
247248

248249
list_del(&entry->list);
249250
entry->start = new_start;
250251
entry->length = new_end - new_start + 1;
251-
iommu_insert_resv_region(entry, regions);
252+
ret = iommu_insert_resv_region(entry, regions);
253+
kfree(entry);
254+
return ret;
252255
} else {
253256
pos = pos->next;
254257
}
@@ -261,7 +264,6 @@ static int iommu_insert_resv_region(struct iommu_resv_region *new,
261264
return -ENOMEM;
262265

263266
list_add_tail(&region->list, pos);
264-
done:
265267
return 0;
266268
}
267269

0 commit comments

Comments
 (0)