Skip to content

Commit 9afea57

Browse files
Chunyan Zhangjoergroedel
authored andcommitted
iommu/sprd: Release dma buffer to avoid memory leak
When attaching to a domain, the driver would alloc a DMA buffer which is used to store address mapping table, and it need to be released when the IOMMU domain is freed. Signed-off-by: Chunyan Zhang <chunyan.zhang@unisoc.com> Link: https://lore.kernel.org/r/20230331033124.864691-2-zhang.lyra@gmail.com Signed-off-by: Joerg Roedel <jroedel@suse.de>
1 parent e8d018d commit 9afea57

1 file changed

Lines changed: 22 additions & 7 deletions

File tree

drivers/iommu/sprd-iommu.c

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -151,13 +151,6 @@ static struct iommu_domain *sprd_iommu_domain_alloc(unsigned int domain_type)
151151
return &dom->domain;
152152
}
153153

154-
static void sprd_iommu_domain_free(struct iommu_domain *domain)
155-
{
156-
struct sprd_iommu_domain *dom = to_sprd_domain(domain);
157-
158-
kfree(dom);
159-
}
160-
161154
static void sprd_iommu_first_vpn(struct sprd_iommu_domain *dom)
162155
{
163156
struct sprd_iommu_device *sdev = dom->sdev;
@@ -230,6 +223,28 @@ static void sprd_iommu_hw_en(struct sprd_iommu_device *sdev, bool en)
230223
sprd_iommu_update_bits(sdev, reg_cfg, mask, 0, val);
231224
}
232225

226+
static void sprd_iommu_cleanup(struct sprd_iommu_domain *dom)
227+
{
228+
size_t pgt_size;
229+
230+
/* Nothing need to do if the domain hasn't been attached */
231+
if (!dom->sdev)
232+
return;
233+
234+
pgt_size = sprd_iommu_pgt_size(&dom->domain);
235+
dma_free_coherent(dom->sdev->dev, pgt_size, dom->pgt_va, dom->pgt_pa);
236+
dom->sdev = NULL;
237+
sprd_iommu_hw_en(dom->sdev, false);
238+
}
239+
240+
static void sprd_iommu_domain_free(struct iommu_domain *domain)
241+
{
242+
struct sprd_iommu_domain *dom = to_sprd_domain(domain);
243+
244+
sprd_iommu_cleanup(dom);
245+
kfree(dom);
246+
}
247+
233248
static int sprd_iommu_attach_device(struct iommu_domain *domain,
234249
struct device *dev)
235250
{

0 commit comments

Comments
 (0)