iommu: Fix a leak in iommu_insert_resv_region
authorEric Auger <eric.auger@redhat.com>
Mon, 3 Jun 2019 06:53:30 +0000 (08:53 +0200)
committerJoerg Roedel <jroedel@suse.de>
Wed, 12 Jun 2019 08:32:23 +0000 (10:32 +0200)
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: 6c65fb318e8b ("iommu: iommu_get_group_resv_regions")
Signed-off-by: Eric Auger <eric.auger@redhat.com>
Signed-off-by: Joerg Roedel <jroedel@suse.de>
drivers/iommu/iommu.c

index 2fca04c3dbafdcc1d639562bc43374c7e349f2bd..ba0661744a3d9373dd5607cd4e102469f9a4dca1 100644 (file)
@@ -237,18 +237,21 @@ static int iommu_insert_resv_region(struct iommu_resv_region *new,
                        pos = pos->next;
                } else if ((start >= a) && (end <= b)) {
                        if (new->type == type)
-                               goto done;
+                               return 0;
                        else
                                pos = pos->next;
                } else {
                        if (new->type == type) {
                                phys_addr_t new_start = min(a, start);
                                phys_addr_t new_end = max(b, end);
+                               int ret;
 
                                list_del(&entry->list);
                                entry->start = new_start;
                                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 {
                                pos = pos->next;
                        }
@@ -261,7 +264,6 @@ insert:
                return -ENOMEM;
 
        list_add_tail(&region->list, pos);
-done:
        return 0;
 }