From 87122bb894b04af347cb7cf8a424b224f8efd5fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Tue, 9 Jun 2026 01:10:33 +0400 Subject: [PATCH] hw/input/ps2: keep QemuInputHandlerState in PS2State MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Track the input handled state, and dispose it on unrealize. Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Marc-André Lureau --- hw/input/ps2.c | 24 ++++++++++++++++++++++-- include/hw/input/ps2.h | 2 ++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/hw/input/ps2.c b/hw/input/ps2.c index f2523ff4bc..97df7a9a43 100644 --- a/hw/input/ps2.c +++ b/hw/input/ps2.c @@ -1233,7 +1233,16 @@ static const QemuInputHandler ps2_keyboard_handler = { static void ps2_kbd_realize(DeviceState *dev, Error **errp) { - qemu_input_handler_register(dev, &ps2_keyboard_handler); + PS2State *s = PS2_DEVICE(dev); + + s->hs = qemu_input_handler_register(dev, &ps2_keyboard_handler); +} + +static void ps2_kbd_unrealize(DeviceState *dev) +{ + PS2State *s = PS2_DEVICE(dev); + + g_clear_pointer(&s->hs, qemu_input_handler_unregister); } static const QemuInputHandler ps2_mouse_handler = { @@ -1245,7 +1254,16 @@ static const QemuInputHandler ps2_mouse_handler = { static void ps2_mouse_realize(DeviceState *dev, Error **errp) { - qemu_input_handler_register(dev, &ps2_mouse_handler); + PS2State *s = PS2_DEVICE(dev); + + s->hs = qemu_input_handler_register(dev, &ps2_mouse_handler); +} + +static void ps2_mouse_unrealize(DeviceState *dev) +{ + PS2State *s = PS2_DEVICE(dev); + + g_clear_pointer(&s->hs, qemu_input_handler_unregister); } static void ps2_kbd_class_init(ObjectClass *klass, const void *data) @@ -1255,6 +1273,7 @@ static void ps2_kbd_class_init(ObjectClass *klass, const void *data) PS2DeviceClass *ps2dc = PS2_DEVICE_CLASS(klass); dc->realize = ps2_kbd_realize; + dc->unrealize = ps2_kbd_unrealize; resettable_class_set_parent_phases(rc, NULL, ps2_kbd_reset_hold, NULL, &ps2dc->parent_phases); dc->vmsd = &vmstate_ps2_keyboard; @@ -1274,6 +1293,7 @@ static void ps2_mouse_class_init(ObjectClass *klass, const void *data) PS2DeviceClass *ps2dc = PS2_DEVICE_CLASS(klass); dc->realize = ps2_mouse_realize; + dc->unrealize = ps2_mouse_unrealize; resettable_class_set_parent_phases(rc, NULL, ps2_mouse_reset_hold, NULL, &ps2dc->parent_phases); dc->vmsd = &vmstate_ps2_mouse; diff --git a/include/hw/input/ps2.h b/include/hw/input/ps2.h index 058db3e089..d0c532a38f 100644 --- a/include/hw/input/ps2.h +++ b/include/hw/input/ps2.h @@ -26,6 +26,7 @@ #define HW_PS2_H #include "hw/core/sysbus.h" +#include "ui/input.h" #define PS2_MOUSE_BUTTON_LEFT 0x01 #define PS2_MOUSE_BUTTON_RIGHT 0x02 @@ -59,6 +60,7 @@ struct PS2State { PS2Queue queue; int32_t write_cmd; qemu_irq irq; + QemuInputHandlerState *hs; }; #define TYPE_PS2_DEVICE "ps2-device"