kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] kvm: Avoid shadowing a local in search_memslots()
@ 2021-10-26 18:19 Qian Cai
  2021-10-27 14:22 ` Sean Christopherson
  0 siblings, 1 reply; 2+ messages in thread
From: Qian Cai @ 2021-10-26 18:19 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: Sean Christopherson, kvm, linux-kernel, Qian Cai

It is less error-prone to use a different variable name from the existing
one in a wider scope. This is also flagged by GCC (W=2):

./include/linux/kvm_host.h: In function 'search_memslots':
./include/linux/kvm_host.h:1246:7: warning: declaration of 'slot' shadows a previous local [-Wshadow]
 1246 |   int slot = start + (end - start) / 2;
      |       ^~~~
./include/linux/kvm_host.h:1240:26: note: shadowed declaration is here
 1240 |  struct kvm_memory_slot *slot;
      |                          ^~~~

Signed-off-by: Qian Cai <quic_qiancai@quicinc.com>
---
 include/linux/kvm_host.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index 60a35d9fe259..9a62c0e52519 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -1243,12 +1243,12 @@ search_memslots(struct kvm_memslots *slots, gfn_t gfn, int *index)
 		return NULL;
 
 	while (start < end) {
-		int slot = start + (end - start) / 2;
+		int pivot = start + (end - start) / 2;
 
-		if (gfn >= memslots[slot].base_gfn)
-			end = slot;
+		if (gfn >= memslots[pivot].base_gfn)
+			end = pivot;
 		else
-			start = slot + 1;
+			start = pivot + 1;
 	}
 
 	slot = try_get_memslot(slots, start, gfn);
-- 
2.30.2


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

* Re: [PATCH v2] kvm: Avoid shadowing a local in search_memslots()
  2021-10-26 18:19 [PATCH v2] kvm: Avoid shadowing a local in search_memslots() Qian Cai
@ 2021-10-27 14:22 ` Sean Christopherson
  0 siblings, 0 replies; 2+ messages in thread
From: Sean Christopherson @ 2021-10-27 14:22 UTC (permalink / raw)
  To: Qian Cai; +Cc: Paolo Bonzini, kvm, linux-kernel

On Tue, Oct 26, 2021, Qian Cai wrote:
> It is less error-prone to use a different variable name from the existing
> one in a wider scope. This is also flagged by GCC (W=2):
> 
> ./include/linux/kvm_host.h: In function 'search_memslots':
> ./include/linux/kvm_host.h:1246:7: warning: declaration of 'slot' shadows a previous local [-Wshadow]
>  1246 |   int slot = start + (end - start) / 2;
>       |       ^~~~
> ./include/linux/kvm_host.h:1240:26: note: shadowed declaration is here
>  1240 |  struct kvm_memory_slot *slot;
>       |                          ^~~~
> 
> Signed-off-by: Qian Cai <quic_qiancai@quicinc.com>
> ---

Reviewed-by: Sean Christopherson <seanjc@google.com>

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

end of thread, other threads:[~2021-10-27 14:23 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-26 18:19 [PATCH v2] kvm: Avoid shadowing a local in search_memslots() Qian Cai
2021-10-27 14:22 ` Sean Christopherson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).