All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] KVM: Don't kfree(NULL) on kzalloc() failure in kvm_assign_ioeventfd_idx()
@ 2023-03-27 17:54 Michal Luczaj
  2023-03-28  4:25 ` Sean Christopherson
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Michal Luczaj @ 2023-03-27 17:54 UTC (permalink / raw)
  To: pbonzini; +Cc: kvm, Michal Luczaj

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(-)

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;
-- 
2.40.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] KVM: Don't kfree(NULL) on kzalloc() failure in kvm_assign_ioeventfd_idx()
  2023-03-27 17:54 [PATCH] KVM: Don't kfree(NULL) on kzalloc() failure in kvm_assign_ioeventfd_idx() Michal Luczaj
@ 2023-03-28  4:25 ` Sean Christopherson
  2023-03-28 17:35 ` Philippe Mathieu-Daudé
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Sean Christopherson @ 2023-03-28  4:25 UTC (permalink / raw)
  To: Michal Luczaj; +Cc: pbonzini, kvm

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>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] KVM: Don't kfree(NULL) on kzalloc() failure in kvm_assign_ioeventfd_idx()
  2023-03-27 17:54 [PATCH] KVM: Don't kfree(NULL) on kzalloc() failure in kvm_assign_ioeventfd_idx() Michal Luczaj
  2023-03-28  4:25 ` Sean Christopherson
@ 2023-03-28 17:35 ` Philippe Mathieu-Daudé
  2023-05-26 11:39 ` Michal Luczaj
  2023-06-02  1:20 ` Sean Christopherson
  3 siblings, 0 replies; 5+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-03-28 17:35 UTC (permalink / raw)
  To: Michal Luczaj, pbonzini; +Cc: kvm

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>


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] KVM: Don't kfree(NULL) on kzalloc() failure in kvm_assign_ioeventfd_idx()
  2023-03-27 17:54 [PATCH] KVM: Don't kfree(NULL) on kzalloc() failure in kvm_assign_ioeventfd_idx() Michal Luczaj
  2023-03-28  4:25 ` Sean Christopherson
  2023-03-28 17:35 ` Philippe Mathieu-Daudé
@ 2023-05-26 11:39 ` Michal Luczaj
  2023-06-02  1:20 ` Sean Christopherson
  3 siblings, 0 replies; 5+ messages in thread
From: Michal Luczaj @ 2023-05-26 11:39 UTC (permalink / raw)
  To: pbonzini; +Cc: kvm

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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] KVM: Don't kfree(NULL) on kzalloc() failure in kvm_assign_ioeventfd_idx()
  2023-03-27 17:54 [PATCH] KVM: Don't kfree(NULL) on kzalloc() failure in kvm_assign_ioeventfd_idx() Michal Luczaj
                   ` (2 preceding siblings ...)
  2023-05-26 11:39 ` Michal Luczaj
@ 2023-06-02  1:20 ` Sean Christopherson
  3 siblings, 0 replies; 5+ messages in thread
From: Sean Christopherson @ 2023-06-02  1:20 UTC (permalink / raw)
  To: Sean Christopherson, pbonzini, Michal Luczaj; +Cc: kvm

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-06-02  1:21 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-03-27 17:54 [PATCH] KVM: Don't kfree(NULL) on kzalloc() failure in kvm_assign_ioeventfd_idx() Michal Luczaj
2023-03-28  4:25 ` Sean Christopherson
2023-03-28 17:35 ` Philippe Mathieu-Daudé
2023-05-26 11:39 ` Michal Luczaj
2023-06-02  1:20 ` Sean Christopherson

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.