From: Jason Wang Date: Tue, 13 Dec 2022 09:07:17 +0000 (+0800) Subject: vdpasim: fix memory leak when freeing IOTLBs X-Git-Tag: v6.1.8~493 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=16b22e27fba6fd816d0dcb98f42cc71f0836c27e;p=platform%2Fkernel%2Flinux-starfive.git vdpasim: fix memory leak when freeing IOTLBs [ Upstream commit 0b7a04a30eef20e6b24926a45c0ce7906ae85bd6 ] After commit bda324fd037a ("vdpasim: control virtqueue support"), vdpasim->iommu became an array of IOTLB, so we should clean the mappings of each free one by one instead of just deleting the ranges in the first IOTLB which may leak maps. Fixes: bda324fd037a ("vdpasim: control virtqueue support") Cc: Gautam Dawar Signed-off-by: Jason Wang Message-Id: <20221213090717.61529-1-jasowang@redhat.com> Signed-off-by: Michael S. Tsirkin Reviewed-by: Gautam Dawar Signed-off-by: Sasha Levin --- diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.c b/drivers/vdpa/vdpa_sim/vdpa_sim.c index b20689f..cb88891 100644 --- a/drivers/vdpa/vdpa_sim/vdpa_sim.c +++ b/drivers/vdpa/vdpa_sim/vdpa_sim.c @@ -689,7 +689,9 @@ static void vdpasim_free(struct vdpa_device *vdpa) } kvfree(vdpasim->buffer); - vhost_iotlb_free(vdpasim->iommu); + for (i = 0; i < vdpasim->dev_attr.nas; i++) + vhost_iotlb_reset(&vdpasim->iommu[i]); + kfree(vdpasim->iommu); kfree(vdpasim->vqs); kfree(vdpasim->config); }