* [PATCH RESEND] virtio_console: Put device on failure
@ 2026-11-25 11:27 Michail Tatas
2026-11-25 11:32 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: Michail Tatas @ 2026-11-25 11:27 UTC (permalink / raw)
To: amit, arnd, gregkh, fan.jiaming; +Cc: virtualization, linux-kernel
If dma_alloc_coherent() fails, the buffer is freed but not the
reference which is acquired before calling dma_alloc_coherent().
Fix by calling put_device in the error path.
Signed-off-by: Michail Tatas <michail.tatas@gmail.com>
---
drivers/char/virtio_console.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
index 62eecfa61646..de83a8a61a8f 100644
--- a/drivers/char/virtio_console.c
+++ b/drivers/char/virtio_console.c
@@ -451,18 +451,22 @@ static struct port_buffer *alloc_buf(struct virtio_device *vdev, size_t buf_size
/* Increase device refcnt to avoid freeing it */
get_device(buf->dev);
buf->buf = dma_alloc_coherent(buf->dev, buf_size, &buf->dma, gfp);
+ if (!buf->buf)
+ goto free_buf_and_put_dev;
} else {
buf->dev = NULL;
buf->buf = kmalloc(buf_size, gfp);
+ if (!buf->buf)
+ goto free_buf;
}
- if (!buf->buf)
- goto free_buf;
buf->len = 0;
buf->offset = 0;
buf->size = buf_size;
return buf;
+free_buf_and_put_dev:
+ put_device(buf->dev);
free_buf:
kfree(buf);
fail:
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH RESEND] virtio_console: Put device on failure
2026-11-25 11:27 [PATCH RESEND] virtio_console: Put device on failure Michail Tatas
@ 2026-11-25 11:32 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-25 11:32 UTC (permalink / raw)
To: Michail Tatas; +Cc: virtualization, Michael S. Tsirkin, Eugenio Perez
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] virtio_console: missing Fixes trailer for alloc_buf() device
refcount fix
--
commit 0d2904b89fd07ffc0b8eae0baa3194301466a9a1
Author: Michail Tatas <michail.tatas@gmail.com>
> virtio_console: Put device on failure
>
> If dma_alloc_coherent() fails, the buffer is freed but not the
> reference which is acquired before calling dma_alloc_coherent().
> Fix by calling put_device in the error path.
>
> Signed-off-by: Michail Tatas <michail.tatas@gmail.com>
[Severity: Low]
This fixes a device reference leak in alloc_buf(). Should the commit
message include:
Fixes: 1b6370463e88 ("virtio_console: Add support for remoteproc serial")
--
Sashiko AI review · https://sashiko.dev/#/patchset/awbGObIpMjR21JSC@michalis-linux?part=1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-25 11:32 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-25 11:27 [PATCH RESEND] virtio_console: Put device on failure Michail Tatas
2026-11-25 11:32 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).