From: Paolo Bonzini <pbonzini@redhat.com>
To: Haiwei Li <lihaiwei.kernel@gmail.com>,
"kvm@vger.kernel.org" <kvm@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] KVM: Add the check and free to avoid unknown errors.
Date: Mon, 17 Feb 2020 18:15:49 +0100 [thread overview]
Message-ID: <33cd2fda-f863-82be-5711-8c9e4eaa7971@redhat.com> (raw)
In-Reply-To: <aaac4289-f6b9-4ee5-eba3-5fe6a4b72645@gmail.com>
On 14/02/20 22:02, Haiwei Li wrote:
> From: Haiwei Li <lihaiwei@tencent.com>
>
> If 'kvm_create_vm_debugfs()' fails in 'kzalloc(sizeof(*stat_data), ...)',
> 'kvm_destroy_vm_debugfs()' will be called by the final fput(file) in
> 'kvm_dev_ioctl_create_vm()'.
Can you explain better? It is okay to pass NULL to kfree.
Paolo
> Add the check and free to avoid unknown errors.
>
> Signed-off-by: Haiwei Li <lihaiwei@tencent.com>
> ---
> virt/kvm/kvm_main.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
> index 67ae2d5..18a32e1 100644
> --- a/virt/kvm/kvm_main.c
> +++ b/virt/kvm/kvm_main.c
> @@ -617,8 +617,11 @@ static void kvm_destroy_vm_debugfs(struct kvm *kvm)
> debugfs_remove_recursive(kvm->debugfs_dentry);
>
> if (kvm->debugfs_stat_data) {
> - for (i = 0; i < kvm_debugfs_num_entries; i++)
> + for (i = 0; i < kvm_debugfs_num_entries; i++) {
> + if (!kvm->debugfs_stat_data[i])
> + break;
> kfree(kvm->debugfs_stat_data[i]);
> + }
> kfree(kvm->debugfs_stat_data);
> }
> }
> --
> 1.8.3.1
>
next prev parent reply other threads:[~2020-02-17 17:15 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-14 21:02 [PATCH] KVM: Add the check and free to avoid unknown errors Haiwei Li
2020-02-17 17:15 ` Paolo Bonzini [this message]
2020-02-15 2:00 linmiaohe
2020-02-15 5:33 ` Haiwei Li
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=33cd2fda-f863-82be-5711-8c9e4eaa7971@redhat.com \
--to=pbonzini@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=lihaiwei.kernel@gmail.com \
--cc=linux-kernel@vger.kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).