* [PATCH] virtio_console: drop device reference when DMA allocation fails
@ 2026-11-23 10:23 Ziheng Wei
2026-11-24 2:47 ` Jiaming Fan
2026-11-24 7:04 ` Ziheng Wei
0 siblings, 2 replies; 4+ messages in thread
From: Ziheng Wei @ 2026-11-23 10:23 UTC (permalink / raw)
To: Amit Shah, Arnd Bergmann, Greg Kroah-Hartman; +Cc: virtualization, linux-kernel
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@163.com>
---
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
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] virtio_console: drop device reference when DMA allocation fails
2026-11-23 10:23 [PATCH] virtio_console: drop device reference when DMA allocation fails Ziheng Wei
@ 2026-11-24 2:47 ` Jiaming Fan
2026-11-24 7:04 ` Ziheng Wei
1 sibling, 0 replies; 4+ messages in thread
From: Jiaming Fan @ 2026-11-24 2:47 UTC (permalink / raw)
To: Ziheng Wei
Cc: Amit Shah, Arnd Bergmann, Greg Kroah-Hartman, virtualization,
linux-kernel
Is this a duplicate of https://lore.kernel.org/all/aoWK_qpSBeO6Bw0M@michalis-linux/?
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] virtio_console: drop device reference when DMA allocation fails
2026-11-23 10:23 [PATCH] virtio_console: drop device reference when DMA allocation fails Ziheng Wei
2026-11-24 2:47 ` Jiaming Fan
@ 2026-11-24 7:04 ` Ziheng Wei
2026-11-24 7:27 ` Greg KH
1 sibling, 1 reply; 4+ messages in thread
From: Ziheng Wei @ 2026-11-24 7:04 UTC (permalink / raw)
To: Jiaming Fan; +Cc: amit, arnd, gregkh, virtualization, linux-kernel
Yes, you are right. This is the same issue and effectively the same fix
as Michail's earlier patch.
I should have found that patch before posting. My duplicate search was
too narrow: I checked the code trees and searched using my own wording,
but did not properly search the mailing-list archives by function and
Fixes tag. That was entirely my oversight.
Please ignore my patch. I am sorry for the duplicate submission and for
the review time it cost you and the other recipients. I will search the
archives more thoroughly before posting future patches.
Ziheng Wei
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-11-24 7:27 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-23 10:23 [PATCH] virtio_console: drop device reference when DMA allocation fails Ziheng Wei
2026-11-24 2:47 ` Jiaming Fan
2026-11-24 7:04 ` Ziheng Wei
2026-11-24 7:27 ` Greg KH
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®