Commit d209ed1570 for qemu.org

commit d209ed157084037dcd1ee982c7427176df7818f1
Author: Marc-André Lureau <marcandre.lureau@redhat.com>
Date:   Sun Feb 22 20:04:52 2026 +0100

    ui/console-vc: extract vt100_init() and vt100_fini()

    Consolidate VT100 initialization and finalization into dedicated
    functions, continuing the extraction of the VT100 layer from the
    console/chardev code.

    vt100_init() gathers the scattered setup (cursor timer, list insertion,
    FIFO creation, default attributes, and image) that was previously spread
    across vc_chr_open() and qemu_text_console_class_init().

    vt100_fini() pairs with it by handling list removal, FIFO destruction,
    and cells cleanup, replacing the open-coded QTAILQ_REMOVE in
    qemu_text_console_finalize().

    Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
    Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>

diff --git a/ui/console-vc.c b/ui/console-vc.c
index 9f5f49413d..b58fe5de82 100644
--- a/ui/console-vc.c
+++ b/ui/console-vc.c
@@ -331,7 +331,7 @@ static void vt100_write(QemuVT100 *vt, const void *buf, size_t len)
     vt->out_flush(vt);
 }

-static int vt100_input(QemuVT100 *vt, const uint8_t *buf, int len);
+static size_t vt100_input(QemuVT100 *vt, const uint8_t *buf, size_t len);

 static void vt100_keysym(QemuVT100 *vt, int keysym)
 {
@@ -1129,12 +1129,19 @@ static void text_console_invalidate(void *opaque)
     vt100_refresh(&s->vt);
 }

+static void vt100_fini(QemuVT100 *vt)
+{
+    QTAILQ_REMOVE(&vt100s, vt, list);
+    fifo8_destroy(&vt->out_fifo);
+    g_free(vt->cells);
+}
+
 static void
 qemu_text_console_finalize(Object *obj)
 {
     QemuTextConsole *s = QEMU_TEXT_CONSOLE(obj);

-    QTAILQ_REMOVE(&vt100s, &s->vt, list);
+    vt100_fini(&s->vt);
 }

 static void
@@ -1142,10 +1149,6 @@ qemu_text_console_class_init(ObjectClass *oc, const void *data)
 {
     QemuConsoleClass *cc = QEMU_CONSOLE_CLASS(oc);

-    if (!cursor_timer) {
-        cursor_timer = timer_new_ms(QEMU_CLOCK_REALTIME, cursor_timer_cb, NULL);
-    }
-
     cc->get_label = qemu_text_console_get_label;
 }

@@ -1211,6 +1214,27 @@ static void text_console_out_flush(QemuVT100 *vt)
     qemu_text_console_out_flush(console);
 }

+static void vt100_init(QemuVT100 *vt,
+                       pixman_image_t *image,
+                       ChardevVCEncoding encoding,
+                       void (*image_update)(QemuVT100 *vt, int x, int y, int w, int h),
+                       void (*out_flush)(QemuVT100 *vt))
+{
+    if (!cursor_timer) {
+        cursor_timer = timer_new_ms(QEMU_CLOCK_REALTIME, cursor_timer_cb, NULL);
+    }
+
+    vt->encoding = encoding;
+    QTAILQ_INSERT_HEAD(&vt100s, vt, list);
+    fifo8_create(&vt->out_fifo, 16);
+    vt->total_height = DEFAULT_BACKSCROLL;
+    vt->image_update = image_update;
+    vt->out_flush = out_flush;
+    /* set current text attributes to default */
+    vt->t_attrib = TEXT_ATTRIBUTES_DEFAULT;
+    vt100_set_image(vt, image);
+}
+
 static bool vc_chr_open(Chardev *chr, ChardevBackend *backend, Error **errp)
 {
     ChardevVC *vc = backend->u.vc.data;
@@ -1240,22 +1264,17 @@ static bool vc_chr_open(Chardev *chr, ChardevBackend *backend, Error **errp)
         s = QEMU_TEXT_CONSOLE(object_new(TYPE_QEMU_FIXED_TEXT_CONSOLE));
     }

-    QTAILQ_INSERT_HEAD(&vt100s, &s->vt, list);
-    fifo8_create(&s->vt.out_fifo, 16);
-    s->vt.total_height = DEFAULT_BACKSCROLL;
     dpy_gfx_replace_surface(QEMU_CONSOLE(s), qemu_create_displaysurface(width, height));
-    s->vt.image_update = text_console_image_update;
-    s->vt.out_flush = text_console_out_flush;
-
-    s->chr = chr;
-    drv->console = s;
     if (vc->has_encoding) {
-        drv->encoding = s->vt.encoding = vc->encoding;
+        drv->encoding = vc->encoding;
     }
+    vt100_init(&s->vt, QEMU_CONSOLE(s)->surface->image,
+               drv->encoding,
+               text_console_image_update,
+               text_console_out_flush);

-    /* set current text attributes to default */
-    s->vt.t_attrib = TEXT_ATTRIBUTES_DEFAULT;
-    vt100_set_image(&s->vt, QEMU_CONSOLE(s)->surface->image);
+    s->chr = chr;
+    drv->console = s;

     if (chr->label) {
         char *msg;