* [PATCH] vduse: Fix error around jumping over a __cleanup() variable
@ 2026-06-10 19:16 Nathan Chancellor
2026-06-11 6:54 ` Michael S. Tsirkin
2026-06-11 10:03 ` David Laight
0 siblings, 2 replies; 3+ messages in thread
From: Nathan Chancellor @ 2026-06-10 19:16 UTC (permalink / raw)
To: Michael S. Tsirkin, Jason Wang, Xuan Zhuo, Eugenio Pérez
Cc: virtualization, linux-kernel, llvm, Nathan Chancellor
When building with clang, there is an error in vduse_vq_kick() from
attempting to jump over a variable declared with the cleanup attribute
using goto:
drivers/vdpa/vdpa_user/vduse_dev.c:566:3: error: cannot jump from this goto statement to its label
566 | goto unlock;
| ^
drivers/vdpa/vdpa_user/vduse_dev.c:568:2: note: jump bypasses initialization of variable with __attribute__((cleanup))
568 | guard(rwsem_read)(&vq->dev->rwsem);
| ^
Jumping over a variable declared with the cleanup attribute does not
prevent the cleanup function from running, it would just result in the
variable being passed uninitialized to the cleanup function .clang
errors instead of generating the invalid code, unlike GCC.
The jump is only present to call spin_unlock(), so convert the
spin_lock() and spin_unlock() calls to an equivalent guard() to avoid
the jump while leaving runtime behavior unchanged, clearing up the
warning.
Fixes: 6c141c034c1b ("vduse: Add suspend")
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
---
drivers/vdpa/vdpa_user/vduse_dev.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/drivers/vdpa/vdpa_user/vduse_dev.c b/drivers/vdpa/vdpa_user/vduse_dev.c
index a257fdcb77b7..0500da043761 100644
--- a/drivers/vdpa/vdpa_user/vduse_dev.c
+++ b/drivers/vdpa/vdpa_user/vduse_dev.c
@@ -561,9 +561,9 @@ static int vduse_vdpa_set_vq_address(struct vdpa_device *vdpa, u16 idx,
static void vduse_vq_kick(struct vduse_virtqueue *vq)
{
- spin_lock(&vq->kick_lock);
+ guard(spinlock)(&vq->kick_lock);
if (!vq->ready)
- goto unlock;
+ return;
guard(rwsem_read)(&vq->dev->rwsem);
if (vq->dev->suspended)
@@ -573,8 +573,6 @@ static void vduse_vq_kick(struct vduse_virtqueue *vq)
eventfd_signal(vq->kickfd);
else
vq->kicked = true;
-unlock:
- spin_unlock(&vq->kick_lock);
}
static void vduse_vq_kick_work(struct work_struct *work)
---
base-commit: 6c141c034c1b0b74a2ca4dd3d6fbb6d9054f6e46
change-id: 20260610-vduse_vq_kick-fix-guard-usage-d1037c331419
Best regards,
--
Cheers,
Nathan
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] vduse: Fix error around jumping over a __cleanup() variable
2026-06-10 19:16 [PATCH] vduse: Fix error around jumping over a __cleanup() variable Nathan Chancellor
@ 2026-06-11 6:54 ` Michael S. Tsirkin
2026-06-11 10:03 ` David Laight
1 sibling, 0 replies; 3+ messages in thread
From: Michael S. Tsirkin @ 2026-06-11 6:54 UTC (permalink / raw)
To: Nathan Chancellor
Cc: Jason Wang, Xuan Zhuo, Eugenio Pérez, virtualization,
linux-kernel, llvm
On Wed, Jun 10, 2026 at 12:16:49PM -0700, Nathan Chancellor wrote:
> When building with clang, there is an error in vduse_vq_kick() from
> attempting to jump over a variable declared with the cleanup attribute
> using goto:
>
> drivers/vdpa/vdpa_user/vduse_dev.c:566:3: error: cannot jump from this goto statement to its label
> 566 | goto unlock;
> | ^
> drivers/vdpa/vdpa_user/vduse_dev.c:568:2: note: jump bypasses initialization of variable with __attribute__((cleanup))
> 568 | guard(rwsem_read)(&vq->dev->rwsem);
> | ^
>
> Jumping over a variable declared with the cleanup attribute does not
> prevent the cleanup function from running, it would just result in the
> variable being passed uninitialized to the cleanup function .clang
> errors instead of generating the invalid code, unlike GCC.
>
> The jump is only present to call spin_unlock(), so convert the
> spin_lock() and spin_unlock() calls to an equivalent guard() to avoid
> the jump while leaving runtime behavior unchanged, clearing up the
> warning.
>
> Fixes: 6c141c034c1b ("vduse: Add suspend")
> Signed-off-by: Nathan Chancellor <nathan@kernel.org>
Eugenio?
> ---
> drivers/vdpa/vdpa_user/vduse_dev.c | 6 ++----
> 1 file changed, 2 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/vdpa/vdpa_user/vduse_dev.c b/drivers/vdpa/vdpa_user/vduse_dev.c
> index a257fdcb77b7..0500da043761 100644
> --- a/drivers/vdpa/vdpa_user/vduse_dev.c
> +++ b/drivers/vdpa/vdpa_user/vduse_dev.c
> @@ -561,9 +561,9 @@ static int vduse_vdpa_set_vq_address(struct vdpa_device *vdpa, u16 idx,
>
> static void vduse_vq_kick(struct vduse_virtqueue *vq)
> {
> - spin_lock(&vq->kick_lock);
> + guard(spinlock)(&vq->kick_lock);
> if (!vq->ready)
> - goto unlock;
> + return;
>
> guard(rwsem_read)(&vq->dev->rwsem);
> if (vq->dev->suspended)
> @@ -573,8 +573,6 @@ static void vduse_vq_kick(struct vduse_virtqueue *vq)
> eventfd_signal(vq->kickfd);
> else
> vq->kicked = true;
> -unlock:
> - spin_unlock(&vq->kick_lock);
> }
>
> static void vduse_vq_kick_work(struct work_struct *work)
>
> ---
> base-commit: 6c141c034c1b0b74a2ca4dd3d6fbb6d9054f6e46
> change-id: 20260610-vduse_vq_kick-fix-guard-usage-d1037c331419
>
> Best regards,
> --
> Cheers,
> Nathan
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] vduse: Fix error around jumping over a __cleanup() variable
2026-06-10 19:16 [PATCH] vduse: Fix error around jumping over a __cleanup() variable Nathan Chancellor
2026-06-11 6:54 ` Michael S. Tsirkin
@ 2026-06-11 10:03 ` David Laight
1 sibling, 0 replies; 3+ messages in thread
From: David Laight @ 2026-06-11 10:03 UTC (permalink / raw)
To: Nathan Chancellor
Cc: Michael S. Tsirkin, Jason Wang, Xuan Zhuo, Eugenio Pérez,
virtualization, linux-kernel, llvm
On Wed, 10 Jun 2026 12:16:49 -0700
Nathan Chancellor <nathan@kernel.org> wrote:
> When building with clang, there is an error in vduse_vq_kick() from
> attempting to jump over a variable declared with the cleanup attribute
> using goto:
.
> Jumping over a variable declared with the cleanup attribute does not
> prevent the cleanup function from running, it would just result in the
> variable being passed uninitialized to the cleanup function .clang
> errors instead of generating the invalid code, unlike GCC.
Does the same apply to variables allocated inside switch statements?
I'm sure I've seen one that wasn't inside an extra block.
David
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-06-11 10:03 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-10 19:16 [PATCH] vduse: Fix error around jumping over a __cleanup() variable Nathan Chancellor
2026-06-11 6:54 ` Michael S. Tsirkin
2026-06-11 10:03 ` David Laight
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox