Skip to content

Commit 960db7f

Browse files
committed
drm: mediatek: use common helper for a scatterlist contiguity check
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> Reviewed-by: Robin Murphy <robin.murphy@arm.com> Acked-by: Chun-Kuang Hu <chunkuang.hu@kernel.org>
1 parent c3d9c17 commit 960db7f

1 file changed

Lines changed: 6 additions & 22 deletions

File tree

‎drivers/gpu/drm/mediatek/mtk_drm_gem.c‎

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -212,37 +212,21 @@ struct drm_gem_object *mtk_gem_prime_import_sg_table(struct drm_device *dev,
212212
struct dma_buf_attachment *attach, struct sg_table *sg)
213213
{
214214
struct mtk_drm_gem_obj *mtk_gem;
215-
int ret;
216-
struct scatterlist *s;
217-
unsigned int i;
218-
dma_addr_t expected;
219215

220-
mtk_gem = mtk_drm_gem_init(dev, attach->dmabuf->size);
216+
/* check if the entries in the sg_table are contiguous */
217+
if (drm_prime_get_contiguous_size(sg) < attach->dmabuf->size) {
218+
DRM_ERROR("sg_table is not contiguous");
219+
return ERR_PTR(-EINVAL);
220+
}
221221

222+
mtk_gem = mtk_drm_gem_init(dev, attach->dmabuf->size);
222223
if (IS_ERR(mtk_gem))
223224
return ERR_CAST(mtk_gem);
224225

225-
expected = sg_dma_address(sg->sgl);
226-
for_each_sg(sg->sgl, s, sg->nents, i) {
227-
if (!sg_dma_len(s))
228-
break;
229-
230-
if (sg_dma_address(s) != expected) {
231-
DRM_ERROR("sg_table is not contiguous");
232-
ret = -EINVAL;
233-
goto err_gem_free;
234-
}
235-
expected = sg_dma_address(s) + sg_dma_len(s);
236-
}
237-
238226
mtk_gem->dma_addr = sg_dma_address(sg->sgl);
239227
mtk_gem->sg = sg;
240228

241229
return &mtk_gem->base;
242-
243-
err_gem_free:
244-
kfree(mtk_gem);
245-
return ERR_PTR(ret);
246230
}
247231

248232
void *mtk_drm_gem_prime_vmap(struct drm_gem_object *obj)

0 commit comments

Comments
 (0)