drivers: video: rockchip: vcodec_dma_map_sg maybe fail
authorJung Zhao <jung.zhao@rock-chips.com>
Thu, 30 Mar 2017 00:55:45 +0000 (00:55 +0000)
committerHuang, Tao <huangtao@rock-chips.com>
Fri, 31 Mar 2017 09:53:25 +0000 (17:53 +0800)
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 <jung.zhao@rock-chips.com>
drivers/video/rockchip/vcodec/vcodec_iommu_drm.c

index aa79a98..23d0342 100644 (file)
@@ -671,9 +671,13 @@ static int vcodec_drm_import(struct vcodec_iommu_session_info *session_info,
                s = sg_next(s);
        }
 
                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;
 
        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;
 
 
        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:
 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:
        dma_buf_detach(drm_buffer->dma_buf, attach);
        dma_buf_put(drm_buffer->dma_buf);
 fail_out: