All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] chardev/pty: fix incorrect return value in char_pty_chr_write
@ 2025-12-25  6:34 luzhipeng
  2025-12-26 11:55 ` Marc-André Lureau
  0 siblings, 1 reply; 3+ messages in thread
From: luzhipeng @ 2025-12-25  6:34 UTC (permalink / raw)
  To: qemu-devel; +Cc: 'Marc-André Lureau', Paolo Bonzini, luzhipeng

In char_pty_chr_write(), when the PTY is not connected (s->connected ==
false), the function attempts a non-blocking poll to check if the fd is 
writable. However, even if the fd is not writable or if io_channel_send()
fails the function unconditionally returns 'len', falsely indicating that
all data was successfully written.

Signed-off-by: luzhipeng <luzhipeng@cestc.cn>
---
 chardev/char-pty.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/chardev/char-pty.c b/chardev/char-pty.c
index 652b0bd9e7..37a20d5f4b 100644
--- a/chardev/char-pty.c
+++ b/chardev/char-pty.c
@@ -124,11 +124,15 @@ static int char_pty_chr_write(Chardev *chr, const uint8_t *buf, int len)
     pfd.revents = 0;
     rc = RETRY_ON_EINTR(g_poll(&pfd, 1, 0));
     g_assert(rc >= 0);
+    if ((pfd.revents & G_IO_HUP) || !(pfd.revents & G_IO_OUT)) {
+        return 0;
+    }
     if (!(pfd.revents & G_IO_HUP) && (pfd.revents & G_IO_OUT)) {
         return io_channel_send(s->ioc, buf, len);
     }
 
-    return len;
+    int ret = io_channel_send(s->ioc, buf, len);
+    return ret;
 }
 
 static GSource *pty_chr_add_watch(Chardev *chr, GIOCondition cond)
-- 
2.45.1.windows.1





^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-01-05 10:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-25  6:34 [PATCH] chardev/pty: fix incorrect return value in char_pty_chr_write luzhipeng
2025-12-26 11:55 ` Marc-André Lureau
2026-01-05 10:20   ` Daniel P. Berrangé

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.