diff mbox series

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

Message ID 20230327175457.735903-1-mhal@rbox.co (mailing list archive)
State New, archived
Headers show
Series KVM: Don't kfree(NULL) on kzalloc() failure in kvm_assign_ioeventfd_idx() | expand

Commit Message

Michal Luczaj March 27, 2023, 5:54 p.m. UTC
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 <mhal@rbox.co>
---
 virt/kvm/eventfd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Sean Christopherson March 28, 2023, 4:25 a.m. UTC | #1
On Mon, Mar 27, 2023, Michal Luczaj wrote:
> On kzalloc() failure, taking the `goto fail` path leads to kfree(NULL).
> Such no-op has no use. Move it out.

Huh, the original commit had the funky code, e.g. it wasn't a case of avoiding
labels or anything.

> Signed-off-by: Michal Luczaj <mhal@rbox.co>
> ---

Reviewed-by: Sean Christopherson <seanjc@google.com>
Philippe Mathieu-Daudé March 28, 2023, 5:35 p.m. UTC | #2
On 27/3/23 19:54, Michal Luczaj wrote:
> 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 <mhal@rbox.co>
> ---
>   virt/kvm/eventfd.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Michal Luczaj May 26, 2023, 11:39 a.m. UTC | #3
On 3/27/23 19:54, Michal Luczaj wrote:
> 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
Sean Christopherson June 2, 2023, 1:20 a.m. UTC | #4
On Mon, 27 Mar 2023 19:54:57 +0200, Michal Luczaj wrote:
> On kzalloc() failure, taking the `goto fail` path leads to kfree(NULL).
> Such no-op has no use. Move it out.
> 
> 

Applied to kvm-x86 generic, thanks!

[1/1] KVM: Don't kfree(NULL) on kzalloc() failure in kvm_assign_ioeventfd_idx()
      https://github.com/kvm-x86/linux/commit/70b0bc4c0a05

--
https://github.com/kvm-x86/linux/tree/next
https://github.com/kvm-x86/linux/tree/fixes
diff mbox series

Patch

diff --git a/virt/kvm/eventfd.c b/virt/kvm/eventfd.c
index 2a3ed401ce46..385368e706e5 100644
--- a/virt/kvm/eventfd.c
+++ b/virt/kvm/eventfd.c
@@ -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;