[Intel-xe] [PATCH] drm/xe: Use kvmalloc_array() instead of kmalloc()

Matthew Brost matthew.brost at intel.com
Mon Jul 24 17:17:44 UTC 2023


On Sat, Jul 22, 2023 at 12:52:24AM -0700, Niranjana Vishwanathapura wrote:
> Use kvmalloc_array() instead of kmalloc() to avoid
> memory allocation failure in xe_vma_userptr_pin_pages().
> 
> Signed-off-by: Niranjana Vishwanathapura <niranjana.vishwanathapura at intel.com>

Change makes sense, just wondering if this failure was ever seen?

Anyways:
Reviewed-by: Matthew Brost <matthew.brost at intel.com>

> ---
>  drivers/gpu/drm/xe/xe_vm.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/gpu/drm/xe/xe_vm.c b/drivers/gpu/drm/xe/xe_vm.c
> index 62a99c393d6b..6429d6e5113d 100644
> --- a/drivers/gpu/drm/xe/xe_vm.c
> +++ b/drivers/gpu/drm/xe/xe_vm.c
> @@ -72,7 +72,7 @@ int xe_vma_userptr_pin_pages(struct xe_vma *vma)
>  	if (notifier_seq == vma->userptr.notifier_seq)
>  		return 0;
>  
> -	pages = kmalloc(sizeof(*pages) * num_pages, GFP_KERNEL);
> +	pages = kvmalloc_array(num_pages, sizeof(*pages), GFP_KERNEL);
>  	if (!pages)
>  		return -ENOMEM;
>  
> @@ -152,7 +152,7 @@ int xe_vma_userptr_pin_pages(struct xe_vma *vma)
>  
>  out:
>  	release_pages(pages, pinned);
> -	kfree(pages);
> +	kvfree(pages);
>  
>  	if (!(ret < 0)) {
>  		vma->userptr.notifier_seq = notifier_seq;
> -- 
> 2.21.0.rc0.32.g243a4c7e27
> 


More information about the Intel-xe mailing list