mirror of
https://github.com/torvalds/linux.git
synced 2026-07-27 09:36:22 +02:00
KVM: VFIO: use mutex guard in kvm_vfio_file_set_spapr_tce()
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 8152f82010 ("fdget(), more trivial conversions"))
Signed-off-by: Carlos López <clopez@suse.de>
Reviewed-by: Alex Williamson <alex@shazbot.org>
Link: https://patch.msgid.link/20260313122040.1413091-5-clopez@suse.de
Signed-off-by: Sean Christopherson <seanjc@google.com>
This commit is contained in:
parent
9a7ff26392
commit
40f0f4bb60
|
|
@ -216,7 +216,6 @@ static int kvm_vfio_file_set_spapr_tce(struct kvm_device *dev,
|
|||
struct kvm_vfio_spapr_tce param;
|
||||
struct kvm_vfio *kv = dev->private;
|
||||
struct kvm_vfio_file *kvf;
|
||||
int ret;
|
||||
|
||||
if (copy_from_user(¶m, arg, sizeof(struct kvm_vfio_spapr_tce)))
|
||||
return -EFAULT;
|
||||
|
|
@ -225,9 +224,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 +232,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
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user