Simplify the lock management in sev_asid_new() by using a mutex guard, automatically releasing the mutex when following the goto. Signed-off-by: Carlos López --- arch/x86/kvm/svm/sev.c | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index 5f46b7f073b0..95430d456a6f 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -232,24 +232,20 @@ static int sev_asid_new(struct kvm_sev_info *sev, unsigned long vm_type) return ret; } - mutex_lock(&sev_bitmap_lock); - + scoped_guard(mutex, &sev_bitmap_lock) { again: - asid = find_next_zero_bit(sev_asid_bitmap, max_asid + 1, min_asid); - if (asid > max_asid) { - if (retry && __sev_recycle_asids(min_asid, max_asid)) { - retry = false; - goto again; + asid = find_next_zero_bit(sev_asid_bitmap, max_asid + 1, min_asid); + if (asid > max_asid) { + if (retry && __sev_recycle_asids(min_asid, max_asid)) { + retry = false; + goto again; + } + ret = -EBUSY; + goto e_uncharge; } - mutex_unlock(&sev_bitmap_lock); - ret = -EBUSY; - goto e_uncharge; + __set_bit(asid, sev_asid_bitmap); } - __set_bit(asid, sev_asid_bitmap); - - mutex_unlock(&sev_bitmap_lock); - sev->asid = asid; return 0; e_uncharge: -- 2.51.0