On 12/19/2025 12:41 PM, Carlos López wrote:
> Simplify the error paths in sev_mem_enc_unregister_region() by using a
> mutex guard, allowing early return instead of using gotos.
>
> Signed-off-by: Carlos López <clopez@suse.de>
Reviewed-by: Pankaj Gupta <pankaj.gupta@amd.com>
> ---
> arch/x86/kvm/svm/sev.c | 20 +++++---------------
> 1 file changed, 5 insertions(+), 15 deletions(-)
>
> diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c
> index 253f2ae24bfc..47ff5267ab01 100644
> --- a/arch/x86/kvm/svm/sev.c
> +++ b/arch/x86/kvm/svm/sev.c
> @@ -2746,35 +2746,25 @@ int sev_mem_enc_unregister_region(struct kvm *kvm,
> struct kvm_enc_region *range)
> {
> struct enc_region *region;
> - int ret;
>
> /* If kvm is mirroring encryption context it isn't responsible for it */
> if (is_mirroring_enc_context(kvm))
> return -EINVAL;
>
> - mutex_lock(&kvm->lock);
> + guard(mutex)(&kvm->lock);
>
> - if (!sev_guest(kvm)) {
> - ret = -ENOTTY;
> - goto failed;
> - }
> + if (!sev_guest(kvm))
> + return -ENOTTY;
>
> region = find_enc_region(kvm, range);
> - if (!region) {
> - ret = -EINVAL;
> - goto failed;
> - }
> + if (!region)
> + return -EINVAL;
>
> sev_writeback_caches(kvm);
>
> __unregister_enc_region_locked(kvm, region);
>
> - mutex_unlock(&kvm->lock);
> return 0;
> -
> -failed:
> - mutex_unlock(&kvm->lock);
> - return ret;
> }
>
> int sev_vm_copy_enc_context_from(struct kvm *kvm, unsigned int source_fd)