dri-devel.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] drm: Use vmalloc_array and vcalloc to simplify code
@ 2025-08-16 14:37 Qianfeng Rong
  2025-08-16 14:37 ` [PATCH 1/2] drm/nouveau: Use vmalloc_array " Qianfeng Rong
  2025-08-16 14:37 ` [PATCH 2/2] drm/radeon: Use vmalloc_array and vcalloc " Qianfeng Rong
  0 siblings, 2 replies; 4+ messages in thread
From: Qianfeng Rong @ 2025-08-16 14:37 UTC (permalink / raw)
  To: Lyude Paul, Danilo Krummrich, David Airlie, Simona Vetter,
	Alex Deucher, Christian König,
	open list:DRM DRIVER FOR NVIDIA GEFORCE/QUADRO GPUS,
	open list:DRM DRIVER FOR NVIDIA GEFORCE/QUADRO GPUS, open list,
	open list:RADEON and AMDGPU DRM DRIVERS
  Cc: Qianfeng Rong

Remove array_size() calls and replace vmalloc() and vzalloc() with
vmalloc_array() and vcalloc() respectively to simplify the code.

vmalloc_array() is also optimized better, resulting in less instructions
being used [1].

[1]: https://lore.kernel.org/lkml/abc66ec5-85a4-47e1-9759-2f60ab111971@vivo.com/

Qianfeng Rong (2):
  drm/nouveau: Use vmalloc_array to simplify code
  drm/radeon: Use vmalloc_array and vcalloc to simplify code

 drivers/gpu/drm/nouveau/nv84_fence.c | 2 +-
 drivers/gpu/drm/radeon/radeon_gart.c | 8 ++++----
 2 files changed, 5 insertions(+), 5 deletions(-)

-- 
2.34.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/2] drm/nouveau: Use vmalloc_array to simplify code
  2025-08-16 14:37 [PATCH 0/2] drm: Use vmalloc_array and vcalloc to simplify code Qianfeng Rong
@ 2025-08-16 14:37 ` Qianfeng Rong
  2025-08-16 14:37 ` [PATCH 2/2] drm/radeon: Use vmalloc_array and vcalloc " Qianfeng Rong
  1 sibling, 0 replies; 4+ messages in thread
From: Qianfeng Rong @ 2025-08-16 14:37 UTC (permalink / raw)
  To: Lyude Paul, Danilo Krummrich, David Airlie, Simona Vetter,
	open list:DRM DRIVER FOR NVIDIA GEFORCE/QUADRO GPUS,
	open list:DRM DRIVER FOR NVIDIA GEFORCE/QUADRO GPUS, open list
  Cc: Qianfeng Rong

Use vmalloc_array() instead of vmalloc() to simplify the functions
nv84_fence_suspend().

vmalloc_array() is also optimized better, resulting in less instructions
being used.

Signed-off-by: Qianfeng Rong <rongqianfeng@vivo.com>
---
 drivers/gpu/drm/nouveau/nv84_fence.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/nouveau/nv84_fence.c b/drivers/gpu/drm/nouveau/nv84_fence.c
index 1765b2cedaf9..63a477e631ae 100644
--- a/drivers/gpu/drm/nouveau/nv84_fence.c
+++ b/drivers/gpu/drm/nouveau/nv84_fence.c
@@ -158,7 +158,7 @@ nv84_fence_suspend(struct nouveau_drm *drm)
 	struct nv84_fence_priv *priv = drm->fence;
 	int i;
 
-	priv->suspend = vmalloc(array_size(sizeof(u32), drm->chan_total));
+	priv->suspend = vmalloc_array(drm->chan_total, sizeof(u32));
 	if (priv->suspend) {
 		for (i = 0; i < drm->chan_total; i++)
 			priv->suspend[i] = nouveau_bo_rd32(priv->bo, i*4);
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] drm/radeon: Use vmalloc_array and vcalloc to simplify code
  2025-08-16 14:37 [PATCH 0/2] drm: Use vmalloc_array and vcalloc to simplify code Qianfeng Rong
  2025-08-16 14:37 ` [PATCH 1/2] drm/nouveau: Use vmalloc_array " Qianfeng Rong
@ 2025-08-16 14:37 ` Qianfeng Rong
  2025-08-18 15:29   ` Alex Deucher
  1 sibling, 1 reply; 4+ messages in thread
From: Qianfeng Rong @ 2025-08-16 14:37 UTC (permalink / raw)
  To: Alex Deucher, Christian König, David Airlie, Simona Vetter,
	open list:RADEON and AMDGPU DRM DRIVERS, open list:DRM DRIVERS,
	open list
  Cc: Qianfeng Rong

Use vcalloc() and vmalloc_array() to simplify the functions
radeon_gart_init().

vmalloc_array() is also optimized better, resulting in less instructions
being used.

Signed-off-by: Qianfeng Rong <rongqianfeng@vivo.com>
---
 drivers/gpu/drm/radeon/radeon_gart.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/radeon/radeon_gart.c b/drivers/gpu/drm/radeon/radeon_gart.c
index 4bb242437ff6..acd89a20f272 100644
--- a/drivers/gpu/drm/radeon/radeon_gart.c
+++ b/drivers/gpu/drm/radeon/radeon_gart.c
@@ -346,14 +346,14 @@ int radeon_gart_init(struct radeon_device *rdev)
 	DRM_INFO("GART: num cpu pages %u, num gpu pages %u\n",
 		 rdev->gart.num_cpu_pages, rdev->gart.num_gpu_pages);
 	/* Allocate pages table */
-	rdev->gart.pages = vzalloc(array_size(sizeof(void *),
-				   rdev->gart.num_cpu_pages));
+	rdev->gart.pages = vcalloc(rdev->gart.num_cpu_pages,
+				   sizeof(void *));
 	if (rdev->gart.pages == NULL) {
 		radeon_gart_fini(rdev);
 		return -ENOMEM;
 	}
-	rdev->gart.pages_entry = vmalloc(array_size(sizeof(uint64_t),
-						    rdev->gart.num_gpu_pages));
+	rdev->gart.pages_entry = vmalloc_array(rdev->gart.num_gpu_pages,
+					       sizeof(uint64_t));
 	if (rdev->gart.pages_entry == NULL) {
 		radeon_gart_fini(rdev);
 		return -ENOMEM;
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 2/2] drm/radeon: Use vmalloc_array and vcalloc to simplify code
  2025-08-16 14:37 ` [PATCH 2/2] drm/radeon: Use vmalloc_array and vcalloc " Qianfeng Rong
@ 2025-08-18 15:29   ` Alex Deucher
  0 siblings, 0 replies; 4+ messages in thread
From: Alex Deucher @ 2025-08-18 15:29 UTC (permalink / raw)
  To: Qianfeng Rong
  Cc: Alex Deucher, Christian König, David Airlie, Simona Vetter,
	open list:RADEON and AMDGPU DRM DRIVERS, open list:DRM DRIVERS,
	open list

Applied.  Thanks!

Alex

On Sat, Aug 16, 2025 at 10:54 AM Qianfeng Rong <rongqianfeng@vivo.com> wrote:
>
> Use vcalloc() and vmalloc_array() to simplify the functions
> radeon_gart_init().
>
> vmalloc_array() is also optimized better, resulting in less instructions
> being used.
>
> Signed-off-by: Qianfeng Rong <rongqianfeng@vivo.com>
> ---
>  drivers/gpu/drm/radeon/radeon_gart.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/gpu/drm/radeon/radeon_gart.c b/drivers/gpu/drm/radeon/radeon_gart.c
> index 4bb242437ff6..acd89a20f272 100644
> --- a/drivers/gpu/drm/radeon/radeon_gart.c
> +++ b/drivers/gpu/drm/radeon/radeon_gart.c
> @@ -346,14 +346,14 @@ int radeon_gart_init(struct radeon_device *rdev)
>         DRM_INFO("GART: num cpu pages %u, num gpu pages %u\n",
>                  rdev->gart.num_cpu_pages, rdev->gart.num_gpu_pages);
>         /* Allocate pages table */
> -       rdev->gart.pages = vzalloc(array_size(sizeof(void *),
> -                                  rdev->gart.num_cpu_pages));
> +       rdev->gart.pages = vcalloc(rdev->gart.num_cpu_pages,
> +                                  sizeof(void *));
>         if (rdev->gart.pages == NULL) {
>                 radeon_gart_fini(rdev);
>                 return -ENOMEM;
>         }
> -       rdev->gart.pages_entry = vmalloc(array_size(sizeof(uint64_t),
> -                                                   rdev->gart.num_gpu_pages));
> +       rdev->gart.pages_entry = vmalloc_array(rdev->gart.num_gpu_pages,
> +                                              sizeof(uint64_t));
>         if (rdev->gart.pages_entry == NULL) {
>                 radeon_gart_fini(rdev);
>                 return -ENOMEM;
> --
> 2.34.1
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-08-18 15:29 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-16 14:37 [PATCH 0/2] drm: Use vmalloc_array and vcalloc to simplify code Qianfeng Rong
2025-08-16 14:37 ` [PATCH 1/2] drm/nouveau: Use vmalloc_array " Qianfeng Rong
2025-08-16 14:37 ` [PATCH 2/2] drm/radeon: Use vmalloc_array and vcalloc " Qianfeng Rong
2025-08-18 15:29   ` Alex Deucher

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).