Skip to content

Commit b0eab97

Browse files
Alex Williamsonawilliam
authored andcommitted
vfio/virtio: Use guard() for bar_mutex in legacy I/O
Convert the bar_mutex acquisition in virtiovf_issue_legacy_rw_cmd() to use guard(), eliminating the out label and goto-based error paths in favor of direct returns. Assisted-by: Claude:claude-opus-4-6 Signed-off-by: Alex Williamson <alex.williamson@nvidia.com> Reviewed-by: Yishai Hadas <yishaih@nvidia.com> Link: https://lore.kernel.org/r/20260414200625.3601509-5-alex.williamson@nvidia.com Signed-off-by: Alex Williamson <alex@shazbot.org>
1 parent b5b268c commit b0eab97

1 file changed

Lines changed: 8 additions & 9 deletions

File tree

drivers/vfio/pci/virtio/legacy_io.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ virtiovf_issue_legacy_rw_cmd(struct virtiovf_pci_core_device *virtvdev,
3434
common = pos < VIRTIO_PCI_CONFIG_OFF(msix_enabled);
3535
/* offset within the relevant configuration area */
3636
offset = common ? pos : pos - VIRTIO_PCI_CONFIG_OFF(msix_enabled);
37-
mutex_lock(&virtvdev->bar_mutex);
37+
38+
guard(mutex)(&virtvdev->bar_mutex);
39+
3840
if (read) {
3941
if (common)
4042
ret = virtio_pci_admin_legacy_common_io_read(pdev, offset,
@@ -43,14 +45,12 @@ virtiovf_issue_legacy_rw_cmd(struct virtiovf_pci_core_device *virtvdev,
4345
ret = virtio_pci_admin_legacy_device_io_read(pdev, offset,
4446
count, bar0_buf + pos);
4547
if (ret)
46-
goto out;
48+
return ret;
4749
if (copy_to_user(buf, bar0_buf + pos, count))
48-
ret = -EFAULT;
50+
return -EFAULT;
4951
} else {
50-
if (copy_from_user(bar0_buf + pos, buf, count)) {
51-
ret = -EFAULT;
52-
goto out;
53-
}
52+
if (copy_from_user(bar0_buf + pos, buf, count))
53+
return -EFAULT;
5454

5555
if (common)
5656
ret = virtio_pci_admin_legacy_common_io_write(pdev, offset,
@@ -59,8 +59,7 @@ virtiovf_issue_legacy_rw_cmd(struct virtiovf_pci_core_device *virtvdev,
5959
ret = virtio_pci_admin_legacy_device_io_write(pdev, offset,
6060
count, bar0_buf + pos);
6161
}
62-
out:
63-
mutex_unlock(&virtvdev->bar_mutex);
62+
6463
return ret;
6564
}
6665

0 commit comments

Comments
 (0)