Message ID | 20200826063316.23486-11-m.szyprowski@samsung.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | None | expand |
On 2020-08-26 07:32, Marek Szyprowski wrote: > Use common helper for checking the contiguity of the imported dma-buf and > do this check before allocating resources, so the error path is simpler. Reviewed-by: Robin Murphy <robin.murphy@arm.com> > Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com> > --- > drivers/gpu/drm/mediatek/mtk_drm_gem.c | 28 ++++++-------------------- > 1 file changed, 6 insertions(+), 22 deletions(-) > > diff --git a/drivers/gpu/drm/mediatek/mtk_drm_gem.c b/drivers/gpu/drm/mediatek/mtk_drm_gem.c > index 6190cc3b7b0d..3654ec732029 100644 > --- a/drivers/gpu/drm/mediatek/mtk_drm_gem.c > +++ b/drivers/gpu/drm/mediatek/mtk_drm_gem.c > @@ -212,37 +212,21 @@ struct drm_gem_object *mtk_gem_prime_import_sg_table(struct drm_device *dev, > struct dma_buf_attachment *attach, struct sg_table *sg) > { > struct mtk_drm_gem_obj *mtk_gem; > - int ret; > - struct scatterlist *s; > - unsigned int i; > - dma_addr_t expected; > > - mtk_gem = mtk_drm_gem_init(dev, attach->dmabuf->size); > + /* check if the entries in the sg_table are contiguous */ > + if (drm_prime_get_contiguous_size(sg) < attach->dmabuf->size) { > + DRM_ERROR("sg_table is not contiguous"); > + return ERR_PTR(-EINVAL); > + } > > + mtk_gem = mtk_drm_gem_init(dev, attach->dmabuf->size); > if (IS_ERR(mtk_gem)) > return ERR_CAST(mtk_gem); > > - expected = sg_dma_address(sg->sgl); > - for_each_sg(sg->sgl, s, sg->nents, i) { > - if (!sg_dma_len(s)) > - break; > - > - if (sg_dma_address(s) != expected) { > - DRM_ERROR("sg_table is not contiguous"); > - ret = -EINVAL; > - goto err_gem_free; > - } > - expected = sg_dma_address(s) + sg_dma_len(s); > - } > - > mtk_gem->dma_addr = sg_dma_address(sg->sgl); > mtk_gem->sg = sg; > > return &mtk_gem->base; > - > -err_gem_free: > - kfree(mtk_gem); > - return ERR_PTR(ret); > } > > void *mtk_drm_gem_prime_vmap(struct drm_gem_object *obj) >
Hi, Marek: Marek Szyprowski <m.szyprowski@samsung.com> 於 2020年8月26日 週三 下午2:35寫道: > > Use common helper for checking the contiguity of the imported dma-buf and > do this check before allocating resources, so the error path is simpler. > Acked-by: Chun-Kuang Hu <chunkuang.hu@kernel.org> > Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com> > --- > drivers/gpu/drm/mediatek/mtk_drm_gem.c | 28 ++++++-------------------- > 1 file changed, 6 insertions(+), 22 deletions(-) > > diff --git a/drivers/gpu/drm/mediatek/mtk_drm_gem.c b/drivers/gpu/drm/mediatek/mtk_drm_gem.c > index 6190cc3b7b0d..3654ec732029 100644 > --- a/drivers/gpu/drm/mediatek/mtk_drm_gem.c > +++ b/drivers/gpu/drm/mediatek/mtk_drm_gem.c > @@ -212,37 +212,21 @@ struct drm_gem_object *mtk_gem_prime_import_sg_table(struct drm_device *dev, > struct dma_buf_attachment *attach, struct sg_table *sg) > { > struct mtk_drm_gem_obj *mtk_gem; > - int ret; > - struct scatterlist *s; > - unsigned int i; > - dma_addr_t expected; > > - mtk_gem = mtk_drm_gem_init(dev, attach->dmabuf->size); > + /* check if the entries in the sg_table are contiguous */ > + if (drm_prime_get_contiguous_size(sg) < attach->dmabuf->size) { > + DRM_ERROR("sg_table is not contiguous"); > + return ERR_PTR(-EINVAL); > + } > > + mtk_gem = mtk_drm_gem_init(dev, attach->dmabuf->size); > if (IS_ERR(mtk_gem)) > return ERR_CAST(mtk_gem); > > - expected = sg_dma_address(sg->sgl); > - for_each_sg(sg->sgl, s, sg->nents, i) { > - if (!sg_dma_len(s)) > - break; > - > - if (sg_dma_address(s) != expected) { > - DRM_ERROR("sg_table is not contiguous"); > - ret = -EINVAL; > - goto err_gem_free; > - } > - expected = sg_dma_address(s) + sg_dma_len(s); > - } > - > mtk_gem->dma_addr = sg_dma_address(sg->sgl); > mtk_gem->sg = sg; > > return &mtk_gem->base; > - > -err_gem_free: > - kfree(mtk_gem); > - return ERR_PTR(ret); > } > > void *mtk_drm_gem_prime_vmap(struct drm_gem_object *obj) > -- > 2.17.1 >
diff --git a/drivers/gpu/drm/mediatek/mtk_drm_gem.c b/drivers/gpu/drm/mediatek/mtk_drm_gem.c index 6190cc3b7b0d..3654ec732029 100644 --- a/drivers/gpu/drm/mediatek/mtk_drm_gem.c +++ b/drivers/gpu/drm/mediatek/mtk_drm_gem.c @@ -212,37 +212,21 @@ struct drm_gem_object *mtk_gem_prime_import_sg_table(struct drm_device *dev, struct dma_buf_attachment *attach, struct sg_table *sg) { struct mtk_drm_gem_obj *mtk_gem; - int ret; - struct scatterlist *s; - unsigned int i; - dma_addr_t expected; - mtk_gem = mtk_drm_gem_init(dev, attach->dmabuf->size); + /* check if the entries in the sg_table are contiguous */ + if (drm_prime_get_contiguous_size(sg) < attach->dmabuf->size) { + DRM_ERROR("sg_table is not contiguous"); + return ERR_PTR(-EINVAL); + } + mtk_gem = mtk_drm_gem_init(dev, attach->dmabuf->size); if (IS_ERR(mtk_gem)) return ERR_CAST(mtk_gem); - expected = sg_dma_address(sg->sgl); - for_each_sg(sg->sgl, s, sg->nents, i) { - if (!sg_dma_len(s)) - break; - - if (sg_dma_address(s) != expected) { - DRM_ERROR("sg_table is not contiguous"); - ret = -EINVAL; - goto err_gem_free; - } - expected = sg_dma_address(s) + sg_dma_len(s); - } - mtk_gem->dma_addr = sg_dma_address(sg->sgl); mtk_gem->sg = sg; return &mtk_gem->base; - -err_gem_free: - kfree(mtk_gem); - return ERR_PTR(ret); } void *mtk_drm_gem_prime_vmap(struct drm_gem_object *obj)
Use common helper for checking the contiguity of the imported dma-buf and do this check before allocating resources, so the error path is simpler. Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com> --- drivers/gpu/drm/mediatek/mtk_drm_gem.c | 28 ++++++-------------------- 1 file changed, 6 insertions(+), 22 deletions(-)