[PATCH] drm/prime: drm_prime_sg_to_dma_addr_array(): Return -EINVAL on error

Sui Jingfeng posted 1 patch 3 weeks, 3 days ago
drivers/gpu/drm/drm_prime.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] drm/prime: drm_prime_sg_to_dma_addr_array(): Return -EINVAL on error
Posted by Sui Jingfeng 3 weeks, 3 days ago
'-EINVAL' stands for invalid argument, while '-1' will accidently be
interpreted as '-EPERM' by the potential upper caller. Which does not
describe the error case accurately, since such an error can happens when
the caller pass a smaller number than actually needed size to describe
the array passed-in. Such an error is invalid argument.

Take drm/vmwgfx driver as an example, the function call trace is:

|- ttm_bo_vmap()
|-- ttm_tt_populate()
|--- bdev->funcs->ttm_tt_populate()
|----- vmw_ttm_populate()
|------ drm_prime_sg_to_dma_addr_array()

While ttm_bo_vmap() requires its callees return '-EINVAL' on invalid range,
similier for other users or call path. Let's meet the requirement.

Signed-off-by: Sui Jingfeng <sui.jingfeng@linux.dev>
---
 drivers/gpu/drm/drm_prime.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/drm_prime.c b/drivers/gpu/drm/drm_prime.c
index 0e3f8adf162f..3f1d516a90b6 100644
--- a/drivers/gpu/drm/drm_prime.c
+++ b/drivers/gpu/drm/drm_prime.c
@@ -1055,7 +1055,7 @@ int drm_prime_sg_to_dma_addr_array(struct sg_table *sgt, dma_addr_t *addrs,
 
 	for_each_sgtable_dma_page(sgt, &dma_iter, 0) {
 		if (WARN_ON(a - addrs >= max_entries))
-			return -1;
+			return -EINVAL;
 		*a++ = sg_page_iter_dma_address(&dma_iter);
 	}
 	return 0;
-- 
2.34.1