All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] KVM: squelch uninitialized variable warning
@ 2020-01-09 19:58 Barret Rhoden
  2020-01-09 22:04 ` Sean Christopherson
  0 siblings, 1 reply; 3+ messages in thread
From: Barret Rhoden @ 2020-01-09 19:58 UTC (permalink / raw)
  To: pbonzini; +Cc: kvm, linux-kernel

If gfn_to_hva_many() fails, __kvm_gfn_to_hva_cache_init() will return an
error.  Before it does, it might use nr_pages_avail, which my compiler
complained about:

	virt/kvm/kvm_main.c:2193:13: warning: 'nr_pages_avail' may be
	used uninitialized in this function [-Wmaybe-uninitialized]

	   start_gfn += nr_pages_avail;

Signed-off-by: Barret Rhoden <brho@google.com>
---
 virt/kvm/kvm_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index d9aced677ddd..f8249b153d33 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -2172,7 +2172,7 @@ static int __kvm_gfn_to_hva_cache_init(struct kvm_memslots *slots,
 	gfn_t start_gfn = gpa >> PAGE_SHIFT;
 	gfn_t end_gfn = (gpa + len - 1) >> PAGE_SHIFT;
 	gfn_t nr_pages_needed = end_gfn - start_gfn + 1;
-	gfn_t nr_pages_avail;
+	gfn_t nr_pages_avail = 0;
 	int r = start_gfn <= end_gfn ? 0 : -EINVAL;
 
 	ghc->gpa = gpa;
-- 
2.25.0.rc1.283.g88dfdc4193-goog


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

* Re: [PATCH] KVM: squelch uninitialized variable warning
  2020-01-09 19:58 [PATCH] KVM: squelch uninitialized variable warning Barret Rhoden
@ 2020-01-09 22:04 ` Sean Christopherson
  2020-01-18 20:19   ` Paolo Bonzini
  0 siblings, 1 reply; 3+ messages in thread
From: Sean Christopherson @ 2020-01-09 22:04 UTC (permalink / raw)
  To: Barret Rhoden; +Cc: pbonzini, kvm, linux-kernel

On Thu, Jan 09, 2020 at 02:58:55PM -0500, Barret Rhoden wrote:
> If gfn_to_hva_many() fails, __kvm_gfn_to_hva_cache_init() will return an
> error.  Before it does, it might use nr_pages_avail, which my compiler
> complained about:
> 
> 	virt/kvm/kvm_main.c:2193:13: warning: 'nr_pages_avail' may be
> 	used uninitialized in this function [-Wmaybe-uninitialized]
> 
> 	   start_gfn += nr_pages_avail;

Ugh, this whole flow is funky.  The change is correct, and is certainly the
minimal change if we want to backport this to stable, but IMO it's putting
lipstick on a pig.  I'd rather fix the underlying issues and make the code
more readable in the process.  I'll send a patch.

If we want to take this as a minimal fix,

Reviewed-by: Sean Christopherson <sean.j.christopherson@intel.com>

> Signed-off-by: Barret Rhoden <brho@google.com>
> ---
>  virt/kvm/kvm_main.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
> index d9aced677ddd..f8249b153d33 100644
> --- a/virt/kvm/kvm_main.c
> +++ b/virt/kvm/kvm_main.c
> @@ -2172,7 +2172,7 @@ static int __kvm_gfn_to_hva_cache_init(struct kvm_memslots *slots,
>  	gfn_t start_gfn = gpa >> PAGE_SHIFT;
>  	gfn_t end_gfn = (gpa + len - 1) >> PAGE_SHIFT;
>  	gfn_t nr_pages_needed = end_gfn - start_gfn + 1;
> -	gfn_t nr_pages_avail;
> +	gfn_t nr_pages_avail = 0;
>  	int r = start_gfn <= end_gfn ? 0 : -EINVAL;
>  
>  	ghc->gpa = gpa;
> -- 
> 2.25.0.rc1.283.g88dfdc4193-goog
> 

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

* Re: [PATCH] KVM: squelch uninitialized variable warning
  2020-01-09 22:04 ` Sean Christopherson
@ 2020-01-18 20:19   ` Paolo Bonzini
  0 siblings, 0 replies; 3+ messages in thread
From: Paolo Bonzini @ 2020-01-18 20:19 UTC (permalink / raw)
  To: Sean Christopherson, Barret Rhoden; +Cc: kvm, linux-kernel

On 09/01/20 23:04, Sean Christopherson wrote:
> Reviewed-by: Sean Christopherson <sean.j.christopherson@intel.com>

Thanks, I queued it so that at least it gets to stable.

Paolo


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

end of thread, other threads:[~2020-01-18 20:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-09 19:58 [PATCH] KVM: squelch uninitialized variable warning Barret Rhoden
2020-01-09 22:04 ` Sean Christopherson
2020-01-18 20:19   ` Paolo Bonzini

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.