All of lore.kernel.org
 help / color / mirror / Atom feed
From: Michail Tatas <michail.tatas@gmail.com>
To: amit@kernel.org, arnd@arndb.de, gregkh@linuxfoundation.org,
	fan.jiaming@hotmail.com
Cc: virtualization@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: [PATCH RESEND] virtio_console: Put device on failure
Date: Wed, 25 Nov 2026 13:27:53 +0200	[thread overview]
Message-ID: <awbGObIpMjR21JSC@michalis-linux> (raw)

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


             reply	other threads:[~2026-11-25 11:27 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25 11:27 Michail Tatas [this message]
2026-11-25 11:32 ` [PATCH RESEND] virtio_console: Put device on failure sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=awbGObIpMjR21JSC@michalis-linux \
    --to=michail.tatas@gmail.com \
    --cc=amit@kernel.org \
    --cc=arnd@arndb.de \
    --cc=fan.jiaming@hotmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=virtualization@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.