[PATCH] virtio_console: drop device reference when DMA allocation fails
From: Ziheng Wei
Date: Mon Nov 23 2026 - 05:24:20 EST
alloc_buf() takes a device reference before dma_alloc_coherent(), but its
failure label only frees the buffer:
get_device() -> dma_alloc_coherent() fails -> kfree(buf)
-> device reference is permanently leaked
Release the reference on the failure path as free_buf() does on success.
Found by LLM-assisted static analysis. Build tested with allmodconfig;
no runtime fault-injection test.
Fixes: 1b6370463e88 ("virtio_console: Add support for remoteproc serial")
Signed-off-by: Ziheng Wei <zihengw03@xxxxxxx>
---
drivers/char/virtio_console.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
index b1b1aaf43..ef942c0df 100644
--- a/drivers/char/virtio_console.c
+++ b/drivers/char/virtio_console.c
@@ -464,6 +464,8 @@ static struct port_buffer *alloc_buf(struct virtio_device *vdev, size_t buf_size
return buf;
free_buf:
+ if (buf->dev)
+ put_device(buf->dev);
kfree(buf);
fail:
return NULL;
base-commit: 97d73c8251226cf27cc6656b4c542869bb8c69fa
--
2.43.0