diff mbox series

[v9,13/32] drm: omapdrm: use common helper for extracting pages array

Message ID 20200826063316.23486-14-m.szyprowski@samsung.com
State Superseded
Headers show
Series DRM: fix struct sg_table nents vs. orig_nents misuse | expand

Commit Message

Marek Szyprowski Aug. 26, 2020, 6:32 a.m. UTC
Use common helper for converting a sg_table object into struct
page pointer array.

Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>

---
 drivers/gpu/drm/omapdrm/omap_gem.c | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)

-- 
2.17.1

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

Comments

Robin Murphy Sept. 1, 2020, 7:17 p.m. UTC | #1
On 2020-08-26 07:32, Marek Szyprowski wrote:
> Use common helper for converting a sg_table object into struct

> page pointer array.

> 

> Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>

> ---

>   drivers/gpu/drm/omapdrm/omap_gem.c | 14 ++++----------

>   1 file changed, 4 insertions(+), 10 deletions(-)

> 

> diff --git a/drivers/gpu/drm/omapdrm/omap_gem.c b/drivers/gpu/drm/omapdrm/omap_gem.c

> index d0d12d5dd76c..ff0c4b0c3fd0 100644

> --- a/drivers/gpu/drm/omapdrm/omap_gem.c

> +++ b/drivers/gpu/drm/omapdrm/omap_gem.c

> @@ -1297,10 +1297,9 @@ struct drm_gem_object *omap_gem_new_dmabuf(struct drm_device *dev, size_t size,

>   		omap_obj->dma_addr = sg_dma_address(sgt->sgl);

>   	} else {

>   		/* Create pages list from sgt */

> -		struct sg_page_iter iter;

>   		struct page **pages;

>   		unsigned int npages;

> -		unsigned int i = 0;

> +		unsigned int ret;

>   

>   		npages = DIV_ROUND_UP(size, PAGE_SIZE);

>   		pages = kcalloc(npages, sizeof(*pages), GFP_KERNEL);

> @@ -1311,14 +1310,9 @@ struct drm_gem_object *omap_gem_new_dmabuf(struct drm_device *dev, size_t size,

>   		}

>   

>   		omap_obj->pages = pages;

> -

> -		for_each_sg_page(sgt->sgl, &iter, sgt->orig_nents, 0) {

> -			pages[i++] = sg_page_iter_page(&iter);

> -			if (i > npages)

> -				break;

> -		}

> -

> -		if (WARN_ON(i != npages)) {

> +		ret = drm_prime_sg_to_page_addr_arrays(sgt, pages, NULL,

> +						       npages);

> +		if (WARN_ON(ret)) {


Again, I'm inclined to think the WARN_ON should remain in 
drm_prime_sg_to_page_addr_arrays() itself such that it could be removed 
here, but either way,

Reviewed-by: Robin Murphy <robin.murphy@arm.com>


>   			omap_gem_free_object(obj);

>   			obj = ERR_PTR(-ENOMEM);

>   			goto done;

> 

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
diff mbox series

Patch

diff --git a/drivers/gpu/drm/omapdrm/omap_gem.c b/drivers/gpu/drm/omapdrm/omap_gem.c
index d0d12d5dd76c..ff0c4b0c3fd0 100644
--- a/drivers/gpu/drm/omapdrm/omap_gem.c
+++ b/drivers/gpu/drm/omapdrm/omap_gem.c
@@ -1297,10 +1297,9 @@  struct drm_gem_object *omap_gem_new_dmabuf(struct drm_device *dev, size_t size,
 		omap_obj->dma_addr = sg_dma_address(sgt->sgl);
 	} else {
 		/* Create pages list from sgt */
-		struct sg_page_iter iter;
 		struct page **pages;
 		unsigned int npages;
-		unsigned int i = 0;
+		unsigned int ret;
 
 		npages = DIV_ROUND_UP(size, PAGE_SIZE);
 		pages = kcalloc(npages, sizeof(*pages), GFP_KERNEL);
@@ -1311,14 +1310,9 @@  struct drm_gem_object *omap_gem_new_dmabuf(struct drm_device *dev, size_t size,
 		}
 
 		omap_obj->pages = pages;
-
-		for_each_sg_page(sgt->sgl, &iter, sgt->orig_nents, 0) {
-			pages[i++] = sg_page_iter_page(&iter);
-			if (i > npages)
-				break;
-		}
-
-		if (WARN_ON(i != npages)) {
+		ret = drm_prime_sg_to_page_addr_arrays(sgt, pages, NULL,
+						       npages);
+		if (WARN_ON(ret)) {
 			omap_gem_free_object(obj);
 			obj = ERR_PTR(-ENOMEM);
 			goto done;