Re: [PATCH] KVM: guest_memfd: Drop a superfluous local var in kvm_gmem_fault_user_mapping()
From: Ackerley Tng
Date: Thu Oct 09 2025 - 19:46:47 EST
Sean Christopherson <seanjc@xxxxxxxxxx> writes:
> Drop the local "int err" that's buried in the middle guest_memfd's user
> fault handler to avoid the potential for variable shadowing, e.g. if an
> "err" variable were also declared at function scope.
>
Is the takeaway here that the variable name "err", if used, should be
defined at function scope?
IOW, would this code have been okay if any other variable name were
used, like if err_folio were used instead of err?
> No functional change intended.
>
> Signed-off-by: Sean Christopherson <seanjc@xxxxxxxxxx>
Reviewed-by: Ackerley Tng <ackerleytng@xxxxxxxxxx>
> ---
> virt/kvm/guest_memfd.c | 6 ++----
> 1 file changed, 2 insertions(+), 4 deletions(-)
>
> diff --git a/virt/kvm/guest_memfd.c b/virt/kvm/guest_memfd.c
> index 94bafd6c558c..abbec01d7a3a 100644
> --- a/virt/kvm/guest_memfd.c
> +++ b/virt/kvm/guest_memfd.c
> @@ -330,12 +330,10 @@ static vm_fault_t kvm_gmem_fault_user_mapping(struct vm_fault *vmf)
>
> folio = kvm_gmem_get_folio(inode, vmf->pgoff);
> if (IS_ERR(folio)) {
> - int err = PTR_ERR(folio);
> -
> - if (err == -EAGAIN)
> + if (PTR_ERR(folio) == -EAGAIN)
> return VM_FAULT_RETRY;
>
> - return vmf_error(err);
> + return vmf_error(PTR_ERR(folio));
> }
>
> if (WARN_ON_ONCE(folio_test_large(folio))) {
>
> base-commit: 6b36119b94d0b2bb8cea9d512017efafd461d6ac