From: Jung Zhao Date: Thu, 30 Mar 2017 00:55:45 +0000 (+0000) Subject: drivers: video: rockchip: vcodec_dma_map_sg maybe fail X-Git-Tag: firefly_0821_release~165 X-Git-Url: http://plrg.eecs.uci.edu/git/?p=firefly-linux-kernel-4.4.55.git;a=commitdiff_plain;h=fa9bd02d2f4b6639914795ec605cb96ac9e2589c drivers: video: rockchip: vcodec_dma_map_sg maybe fail switching front and rear camera, maybe cause memory exhausted. in this case, vpu driver must print a warning. Change-Id: I60f3bfb662f42025624988a5a09ce7f69b358ea6 Signed-off-by: Jung Zhao --- diff --git a/drivers/video/rockchip/vcodec/vcodec_iommu_drm.c b/drivers/video/rockchip/vcodec/vcodec_iommu_drm.c index aa79a98b7622..23d03427ef1b 100644 --- a/drivers/video/rockchip/vcodec/vcodec_iommu_drm.c +++ b/drivers/video/rockchip/vcodec/vcodec_iommu_drm.c @@ -671,9 +671,13 @@ static int vcodec_drm_import(struct vcodec_iommu_session_info *session_info, s = sg_next(s); } - vcodec_dma_map_sg(drm_info->domain, drm_buffer->copy_sgt->sgl, - drm_buffer->copy_sgt->nents, - IOMMU_READ | IOMMU_WRITE); + ret = vcodec_dma_map_sg(drm_info->domain, drm_buffer->copy_sgt->sgl, + drm_buffer->copy_sgt->nents, + IOMMU_READ | IOMMU_WRITE); + if (!ret) { + ret = -ENOMEM; + goto fail_alloc; + } drm_buffer->iova = sg_dma_address(drm_buffer->copy_sgt->sgl); drm_buffer->size = drm_buffer->dma_buf->size; @@ -712,8 +716,12 @@ static int vcodec_drm_import(struct vcodec_iommu_session_info *session_info, return drm_buffer->index; +fail_alloc: + sg_free_table(drm_buffer->copy_sgt); + kfree(drm_buffer->copy_sgt); + dma_buf_unmap_attachment(attach, sgt, + DMA_BIDIRECTIONAL); fail_detach: - dev_err(dev, "dmabuf map attach failed\n"); dma_buf_detach(drm_buffer->dma_buf, attach); dma_buf_put(drm_buffer->dma_buf); fail_out: