From: Russell King <rmk+kernel@xxxxxxxxxxxxxxxx> If etnaviv_iommu_map() fails, we returned an error, but we didn't clean up the allocated drm_mm node. Simplify the return path and add the necessary failure clean up. Signed-off-by: Russell King <rmk+kernel@xxxxxxxxxxxxxxxx> --- drivers/staging/etnaviv/etnaviv_mmu.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/drivers/staging/etnaviv/etnaviv_mmu.c b/drivers/staging/etnaviv/etnaviv_mmu.c index 4fbba26a3f37..89c5713f52bc 100644 --- a/drivers/staging/etnaviv/etnaviv_mmu.c +++ b/drivers/staging/etnaviv/etnaviv_mmu.c @@ -95,8 +95,7 @@ int etnaviv_iommu_map_gem(struct etnaviv_iommu *mmu, struct etnaviv_gem_object *etnaviv_obj) { struct sg_table *sgt = etnaviv_obj->sgt; - uint32_t offset; - struct drm_mm_node *node = NULL; + struct drm_mm_node *node; int ret; /* v1 MMU can optimize single entry (contiguous) scatterlists */ @@ -138,18 +137,25 @@ int etnaviv_iommu_map_gem(struct etnaviv_iommu *mmu, break; } - if (!ret) { - mmu->last_iova = node->start + etnaviv_obj->base.size; - offset = node->start; - etnaviv_obj->iova = offset; - etnaviv_obj->gpu_vram_node = node; + if (ret < 0) { + kfree(node); + return ret; + } + + mmu->last_iova = node->start + etnaviv_obj->base.size; + etnaviv_obj->iova = node->start; + etnaviv_obj->gpu_vram_node = node; + ret = etnaviv_iommu_map(mmu, node->start, sgt, etnaviv_obj->base.size, + IOMMU_READ | IOMMU_WRITE); - ret = etnaviv_iommu_map(mmu, offset, sgt, - etnaviv_obj->base.size, - IOMMU_READ | IOMMU_WRITE); - } else + if (ret < 0) { + drm_mm_remove_node(node); kfree(node); + etnaviv_obj->iova = 0; + etnaviv_obj->gpu_vram_node = NULL; + } + return ret; } -- 2.1.4 _______________________________________________ dri-devel mailing list dri-devel@xxxxxxxxxxxxxxxxxxxxx http://lists.freedesktop.org/mailman/listinfo/dri-devel