Skip to content

Commit

Permalink
iommu: rockchip: Free domain on .domain_free
Browse files Browse the repository at this point in the history
IOMMU domain resource life is well-defined, managed
by .domain_alloc and .domain_free.

Therefore, domain-specific resources shouldn't be tied to
the device life, but instead to its domain.

Signed-off-by: Ezequiel Garcia <ezequiel@collabora.com>
Reviewed-by: Robin Murphy <robin.murphy@arm.com>
Acked-by: Heiko Stuebner <heiko@sntech.de>
Signed-off-by: Joerg Roedel <jroedel@suse.de>
  • Loading branch information
Ezequiel Garcia authored and Joerg Roedel committed Oct 16, 2019
1 parent 4f5cafb commit 42bb97b
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions drivers/iommu/rockchip-iommu.c
Original file line number Diff line number Diff line change
Expand Up @@ -979,13 +979,13 @@ static struct iommu_domain *rk_iommu_domain_alloc(unsigned type)
if (!dma_dev)
return NULL;

rk_domain = devm_kzalloc(dma_dev, sizeof(*rk_domain), GFP_KERNEL);
rk_domain = kzalloc(sizeof(*rk_domain), GFP_KERNEL);
if (!rk_domain)
return NULL;

if (type == IOMMU_DOMAIN_DMA &&
iommu_get_dma_cookie(&rk_domain->domain))
return NULL;
goto err_free_domain;

/*
* rk32xx iommus use a 2 level pagetable.
Expand Down Expand Up @@ -1020,6 +1020,8 @@ static struct iommu_domain *rk_iommu_domain_alloc(unsigned type)
err_put_cookie:
if (type == IOMMU_DOMAIN_DMA)
iommu_put_dma_cookie(&rk_domain->domain);
err_free_domain:
kfree(rk_domain);

return NULL;
}
Expand Down Expand Up @@ -1048,6 +1050,7 @@ static void rk_iommu_domain_free(struct iommu_domain *domain)

if (domain->type == IOMMU_DOMAIN_DMA)
iommu_put_dma_cookie(&rk_domain->domain);
kfree(rk_domain);
}

static int rk_iommu_add_device(struct device *dev)
Expand Down

0 comments on commit 42bb97b

Please sign in to comment.