summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Williamson <alex.williamson@nvidia.com>2026-04-14 23:06:21 +0300
committerAlex Williamson <alex@shazbot.org>2026-04-21 21:01:21 +0300
commitb5b268cb7868b598e53eeebd36174c8b27d4cd86 (patch)
treebe2d0f50dd4a8cdf14dcebf78121512ea6c06612
parent61fcb51fc9d576ec367e8aea9c03dc6a746e395e (diff)
downloadlinux-b5b268cb7868b598e53eeebd36174c8b27d4cd86.tar.xz
vfio/virtio: Use guard() for migf->lock where applicable
Convert migf->lock acquisitions in virtiovf_disable_fd() and virtiovf_save_read() to use guard(). In virtiovf_save_read() this eliminates the out_unlock label and multiple goto paths by allowing direct returns, and removes the need for the done variable to double as an error carrier. 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-4-alex.williamson@nvidia.com Signed-off-by: Alex Williamson <alex@shazbot.org>
-rw-r--r--drivers/vfio/pci/virtio/migrate.c40
1 files changed, 14 insertions, 26 deletions
diff --git a/drivers/vfio/pci/virtio/migrate.c b/drivers/vfio/pci/virtio/migrate.c
index 601ef4865ed4..4b1e5502f0a7 100644
--- a/drivers/vfio/pci/virtio/migrate.c
+++ b/drivers/vfio/pci/virtio/migrate.c
@@ -224,10 +224,9 @@ static void virtiovf_clean_migf_resources(struct virtiovf_migration_file *migf)
static void virtiovf_disable_fd(struct virtiovf_migration_file *migf)
{
- mutex_lock(&migf->lock);
+ guard(mutex)(&migf->lock);
migf->state = VIRTIOVF_MIGF_STATE_ERROR;
migf->filp->f_pos = 0;
- mutex_unlock(&migf->lock);
}
static void virtiovf_disable_fds(struct virtiovf_pci_core_device *virtvdev)
@@ -385,11 +384,10 @@ static ssize_t virtiovf_save_read(struct file *filp, char __user *buf, size_t le
return -ESPIPE;
pos = &filp->f_pos;
- mutex_lock(&migf->lock);
- if (migf->state == VIRTIOVF_MIGF_STATE_ERROR) {
- done = -ENODEV;
- goto out_unlock;
- }
+ guard(mutex)(&migf->lock);
+
+ if (migf->state == VIRTIOVF_MIGF_STATE_ERROR)
+ return -ENODEV;
while (len) {
ssize_t count;
@@ -398,34 +396,24 @@ static ssize_t virtiovf_save_read(struct file *filp, char __user *buf, size_t le
if (first_loop_call) {
first_loop_call = false;
/* Temporary end of file as part of PRE_COPY */
- if (end_of_data && migf->state == VIRTIOVF_MIGF_STATE_PRECOPY) {
- done = -ENOMSG;
- goto out_unlock;
- }
- if (end_of_data && migf->state != VIRTIOVF_MIGF_STATE_COMPLETE) {
- done = -EINVAL;
- goto out_unlock;
- }
+ if (end_of_data && migf->state == VIRTIOVF_MIGF_STATE_PRECOPY)
+ return -ENOMSG;
+ if (end_of_data && migf->state != VIRTIOVF_MIGF_STATE_COMPLETE)
+ return -EINVAL;
}
if (end_of_data)
- goto out_unlock;
+ return done;
- if (!vhca_buf) {
- done = -EINVAL;
- goto out_unlock;
- }
+ if (!vhca_buf)
+ return -EINVAL;
count = virtiovf_buf_read(vhca_buf, &buf, &len, pos);
- if (count < 0) {
- done = count;
- goto out_unlock;
- }
+ if (count < 0)
+ return count;
done += count;
}
-out_unlock:
- mutex_unlock(&migf->lock);
return done;
}