From: Carlos López Date: Fri, 13 Mar 2026 12:20:40 +0000 (+0100) Subject: KVM: VFIO: use mutex guard in kvm_vfio_file_set_spapr_tce() X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=40f0f4bb6041b1f520445a4c5f0c8777f7c98f8e;p=thirdparty%2Fkernel%2Flinux.git 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 8152f8201088 ("fdget(), more trivial conversions")) Signed-off-by: Carlos López Reviewed-by: Alex Williamson Link: https://patch.msgid.link/20260313122040.1413091-5-clopez@suse.de Signed-off-by: Sean Christopherson --- diff --git a/virt/kvm/vfio.c b/virt/kvm/vfio.c index 2c91bad3333b..e0d621567dbf 100644 --- a/virt/kvm/vfio.c +++ b/virt/kvm/vfio.c @@ -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