From 70b0bc4c0a05cb68ffeeaba8c8340896b5ff6fd7 Mon Sep 17 00:00:00 2001 From: Michal Luczaj Date: Mon, 27 Mar 2023 19:54:57 +0200 Subject: [PATCH] KVM: Don't kfree(NULL) on kzalloc() failure in kvm_assign_ioeventfd_idx() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On kzalloc() failure, taking the `goto fail` path leads to kfree(NULL). Such no-op has no use. Move it out. Signed-off-by: Michal Luczaj Reviewed-by: Sean Christopherson Reviewed-by: Philippe Mathieu-Daudé Link: https://lore.kernel.org/r/20230327175457.735903-1-mhal@rbox.co Signed-off-by: Sean Christopherson --- virt/kvm/eventfd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/virt/kvm/eventfd.c b/virt/kvm/eventfd.c index b0af834ffa95..7c42441425cf 100644 --- a/virt/kvm/eventfd.c +++ b/virt/kvm/eventfd.c @@ -889,9 +889,9 @@ static int kvm_assign_ioeventfd_idx(struct kvm *kvm, unlock_fail: mutex_unlock(&kvm->slots_lock); + kfree(p); fail: - kfree(p); eventfd_ctx_put(eventfd); return ret;