From: Alex Williamson <alex.williamson@nvidia.com>
To: <alex@shazbot.org>
Cc: Alex Williamson <alex.williamson@nvidia.com>,
<yishaih@nvidia.com>, <kvm@vger.kernel.org>,
<guojinhui.liam@bytedance.com>, <linux-kernel@vger.kernel.org>,
<virtualization@lists.linux.dev>
Subject: [PATCH 3/4] vfio/virtio: Use guard() for migf->lock where applicable
Date: Tue, 14 Apr 2026 14:06:21 -0600 [thread overview]
Message-ID: <20260414200625.3601509-4-alex.williamson@nvidia.com> (raw)
In-Reply-To: <20260414200625.3601509-1-alex.williamson@nvidia.com>
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>
---
drivers/vfio/pci/virtio/migrate.c | 40 +++++++++++--------------------
1 file changed, 14 insertions(+), 26 deletions(-)
diff --git a/drivers/vfio/pci/virtio/migrate.c b/drivers/vfio/pci/virtio/migrate.c
index 058d359c9b5a..80ca8a1b625a 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;
}
--
2.51.0
next prev parent reply other threads:[~2026-04-14 20:07 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-14 20:06 [PATCH 0/4] vfio/virtio: Fix list_lock type and modernize locking Alex Williamson
2026-04-14 20:06 ` [PATCH 1/4] vfio/virtio: Convert list_lock from spinlock to mutex Alex Williamson
2026-04-14 20:06 ` [PATCH 2/4] vfio/virtio: Use guard() for list_lock where applicable Alex Williamson
2026-04-14 20:06 ` Alex Williamson [this message]
2026-04-14 20:06 ` [PATCH 4/4] vfio/virtio: Use guard() for bar_mutex in legacy I/O Alex Williamson
2026-04-15 15:12 ` [PATCH 0/4] vfio/virtio: Fix list_lock type and modernize locking Yishai Hadas
2026-04-15 15:39 ` Alex Williamson
2026-04-15 17:23 ` Yishai Hadas
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260414200625.3601509-4-alex.williamson@nvidia.com \
--to=alex.williamson@nvidia.com \
--cc=alex@shazbot.org \
--cc=guojinhui.liam@bytedance.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=virtualization@lists.linux.dev \
--cc=yishaih@nvidia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox