Skip to contentSkip to conversation

KVM: Don't kfree(NULL) on kzalloc() failure in kvm_assign_ioeventfd_idx()

PATCH Applied Michal Luczaj 3 participants 5 messages Mar 27, 2023 – Jun 2, 2023 KVM

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 KVM: Don't kfree(NULL) on kzalloc() failure in kvm_assign_ioeventfd_idx()

On kzalloc() failure, taking the goto fail path leads to kfree(NULL). Such no-op has no use. Move it out.

---
 virt/kvm/eventfd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
virt/kvm/eventfd.c +1 -1
index 2a3ed401ce46..385368e706e5 100644
@@ -856,9 +856,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;
Signature · 1 line
2.40.0
#3 lore raw
In reply to Michal Luczaj
Quoted 2 lines · Michal Luczaj

On kzalloc() failure, taking the goto fail path leads to kfree(NULL). Such no-op has no use. Move it out.

Few weeks later, a polite ping.

thanks,
Michal