public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Oliver Upton <oupton@google.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org
Subject: Re: [PATCH] KVM: use kvcalloc for array allocations
Date: Tue, 8 Mar 2022 17:43:16 +0000	[thread overview]
Message-ID: <YieVtBPtKOyatej+@google.com> (raw)
In-Reply-To: <20220308163318.819164-1-pbonzini@redhat.com>

On Tue, Mar 08, 2022 at 11:33:18AM -0500, Paolo Bonzini wrote:
> Instead of using array_size, use a function that takes care of the
> multiplication.  While at it, switch to kvcalloc since this allocation
> should not be very large.
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  arch/x86/kvm/cpuid.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
> index afcdd4e693e5..419eb8e14f79 100644
> --- a/arch/x86/kvm/cpuid.c
> +++ b/arch/x86/kvm/cpuid.c
> @@ -1248,8 +1248,7 @@ int kvm_dev_ioctl_get_cpuid(struct kvm_cpuid2 *cpuid,
>  	if (sanity_check_entries(entries, cpuid->nent, type))
>  		return -EINVAL;
>  
> -	array.entries = vzalloc(array_size(sizeof(struct kvm_cpuid_entry2),
> -					   cpuid->nent));
> +	array.entries = kvcalloc(sizeof(struct kvm_cpuid_entry2), cpuid->nent, GFP_KERNEL);

Even though this allocation is short-lived, should we use
GFP_KERNEL_ACCOUNT instead?

Otherwise:

Reviewed-by: Oliver Upton <oupton@google.com>

Thanks!


>  	if (!array.entries)
>  		return -ENOMEM;
>  
> @@ -1267,7 +1266,7 @@ int kvm_dev_ioctl_get_cpuid(struct kvm_cpuid2 *cpuid,
>  		r = -EFAULT;
>  
>  out_free:
> -	vfree(array.entries);
> +	kvfree(array.entries);
>  	return r;
>  }
>  
> -- 
> 2.31.1
> 

  reply	other threads:[~2022-03-08 17:43 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-08 16:33 [PATCH] KVM: use kvcalloc for array allocations Paolo Bonzini
2022-03-08 17:43 ` Oliver Upton [this message]
  -- strict thread matches above, loose matches on Subject: below --
2022-03-30  2:55 Zhiguang Ni

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YieVtBPtKOyatej+@google.com \
    --to=oupton@google.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox