Skip to content

Commit

Permalink
vfio/type1: Fix leak on error path
Browse files Browse the repository at this point in the history
We also don't handle unpinning zero pages as an error on other exits
so we can fix that inconsistency by rolling in the next conditional
return.

Reported-by: Dan Carpenter <[email protected]>
Signed-off-by: Alex Williamson <[email protected]>
  • Loading branch information
awilliam committed Jul 1, 2013
1 parent 6d6768c commit 8d38ef1
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions drivers/vfio/vfio_iommu_type1.c
Original file line number Diff line number Diff line change
Expand Up @@ -436,19 +436,22 @@ static int vfio_remove_dma_overlap(struct vfio_iommu *iommu, dma_addr_t start,
}

/* Split existing */

/*
* Allocate our tracking structure early even though it may not
* be used. An Allocation failure later loses track of pages and
* is more difficult to unwind.
*/
split = kzalloc(sizeof(*split), GFP_KERNEL);
if (!split)
return -ENOMEM;

offset = start - dma->iova;

ret = vfio_unmap_unpin(iommu, dma, start, size);
if (ret)
return ret;

if (!*size) {
if (ret || !*size) {
kfree(split);
return -EINVAL;
return ret;
}

tmp = dma->size;
Expand Down

0 comments on commit 8d38ef1

Please sign in to comment.