@samitouri / QOSamiQemu / commits / 87122bb894

hw/input/ps2: keep QemuInputHandlerState in PS2State

Track the input handled state, and dispose it on unrealize. Reviewed-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>

Marc-André Lureau committed Jun 9, 2026 at 01:10 UTC 87122bb894b04af347cb7cf8a424b224f8efd5fa
2 files changed +24 -2
hw/input/ps2.c
+22 -2
@@ -1233,7 +1233,16 @@ static const QemuInputHandler ps2_keyboard_handler = {
1233
1234 static void ps2_kbd_realize(DeviceState *dev, Error **errp)
1235 {
1236 - qemu_input_handler_register(dev, &ps2_keyboard_handler);
1236 + PS2State *s = PS2_DEVICE(dev);
1237 +
1238 + s->hs = qemu_input_handler_register(dev, &ps2_keyboard_handler);
1239 +}
1240 +
1241 +static void ps2_kbd_unrealize(DeviceState *dev)
1242 +{
1243 + PS2State *s = PS2_DEVICE(dev);
1244 +
1245 + g_clear_pointer(&s->hs, qemu_input_handler_unregister);
1246 }
1247
1248 static const QemuInputHandler ps2_mouse_handler = {
@@ -1245,7 +1254,16 @@ static const QemuInputHandler ps2_mouse_handler = {
1254
1255 static void ps2_mouse_realize(DeviceState *dev, Error **errp)
1256 {
1248 - qemu_input_handler_register(dev, &ps2_mouse_handler);
1257 + PS2State *s = PS2_DEVICE(dev);
1258 +
1259 + s->hs = qemu_input_handler_register(dev, &ps2_mouse_handler);
1260 +}
1261 +
1262 +static void ps2_mouse_unrealize(DeviceState *dev)
1263 +{
1264 + PS2State *s = PS2_DEVICE(dev);
1265 +
1266 + g_clear_pointer(&s->hs, qemu_input_handler_unregister);
1267 }
1268
1269 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)
1273 PS2DeviceClass *ps2dc = PS2_DEVICE_CLASS(klass);
1274
1275 dc->realize = ps2_kbd_realize;
1276 + dc->unrealize = ps2_kbd_unrealize;
1277 resettable_class_set_parent_phases(rc, NULL, ps2_kbd_reset_hold, NULL,
1278 &ps2dc->parent_phases);
1279 dc->vmsd = &vmstate_ps2_keyboard;
@@ -1274,6 +1293,7 @@ static void ps2_mouse_class_init(ObjectClass *klass, const void *data)
1293 PS2DeviceClass *ps2dc = PS2_DEVICE_CLASS(klass);
1294
1295 dc->realize = ps2_mouse_realize;
1296 + dc->unrealize = ps2_mouse_unrealize;
1297 resettable_class_set_parent_phases(rc, NULL, ps2_mouse_reset_hold, NULL,
1298 &ps2dc->parent_phases);
1299 dc->vmsd = &vmstate_ps2_mouse;
include/hw/input/ps2.h
+2
@@ -26,6 +26,7 @@
26 #define HW_PS2_H
27
28 #include "hw/core/sysbus.h"
29 +#include "ui/input.h"
30
31 #define PS2_MOUSE_BUTTON_LEFT 0x01
32 #define PS2_MOUSE_BUTTON_RIGHT 0x02
@@ -59,6 +60,7 @@ struct PS2State {
60 PS2Queue queue;
61 int32_t write_cmd;
62 qemu_irq irq;
63 + QemuInputHandlerState *hs;
64 };
65
66 #define TYPE_PS2_DEVICE "ps2-device"