virtio_console: Put device on failure
Subsystems (3)
PATCH RESEND 1/1 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.
--- drivers/char/virtio_console.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/char/virtio_console.c +6 -2
@@ -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:
Signature · 1 line
2.43.0
[email protected]
AI reviewThank 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 --
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 <[email protected]>
Quoted 7 lines
virtio_console: Put device on failureIf
dma_alloc_coherent()fails, the buffer is freed but not the reference which is acquired before callingdma_alloc_coherent(). Fix by callingput_devicein the error path.Signed-off-by Michail Tatas <[email protected]>
[Severity: Low]
This fixes a device reference leak in alloc_buf(). Should the commit message include:
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/awbGObIpMjR21JSC@michalis-linux?part=1