[PATCH 2/4] KVM: VFIO: use mutex guard in kvm_vfio_file_set_spapr_tce()
From: Carlos López
Date: Fri Mar 13 2026 - 08:24:22 EST
Use a mutex guard to hold a lock for the entirety of the function, which
removes the need for a goto (whose label even has a misleading name
since 8152f8201088 ("fdget(), more trivial conversions"))
Signed-off-by: Carlos López <clopez@xxxxxxx>
---
virt/kvm/vfio.c | 19 ++++++-------------
1 file changed, 6 insertions(+), 13 deletions(-)
diff --git a/virt/kvm/vfio.c b/virt/kvm/vfio.c
index 2c91bad3333b..02d373f66cba 100644
--- a/virt/kvm/vfio.c
+++ b/virt/kvm/vfio.c
@@ -225,9 +225,7 @@ static int kvm_vfio_file_set_spapr_tce(struct kvm_device *dev,
if (fd_empty(f))
return -EBADF;
- ret = -ENOENT;
-
- mutex_lock(&kv->lock);
+ guard(mutex)(&kv->lock);
list_for_each_entry(kvf, &kv->file_list, node) {
if (kvf->file != fd_file(f))
@@ -235,20 +233,15 @@ static int kvm_vfio_file_set_spapr_tce(struct kvm_device *dev,
if (!kvf->iommu_group) {
kvf->iommu_group = kvm_vfio_file_iommu_group(kvf->file);
- if (WARN_ON_ONCE(!kvf->iommu_group)) {
- ret = -EIO;
- goto err_fdput;
- }
+ if (WARN_ON_ONCE(!kvf->iommu_group))
+ return -EIO;
}
- ret = kvm_spapr_tce_attach_iommu_group(dev->kvm, param.tablefd,
- kvf->iommu_group);
- break;
+ return kvm_spapr_tce_attach_iommu_group(dev->kvm, param.tablefd,
+ kvf->iommu_group);
}
-err_fdput:
- mutex_unlock(&kv->lock);
- return ret;
+ return -ENOENT;
}
#endif
--
2.51.0