@samitouri / QOSamiQemu / commits / 4944ca9914

hw/input: keep QemuInputHandlerState in stellaris

Track the input handled state, and dispose it on unrealize. Also free some allocated fields during 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 4944ca9914a6c0f1cb9980fa51b7d0e793a537c6
2 files changed +13 -1
hw/input/stellaris_gamepad.c
+11 -1
@@ -59,7 +59,16 @@ static void stellaris_gamepad_realize(DeviceState *dev, Error **errp)
59 s->irqs = g_new0(qemu_irq, s->num_buttons);
60 s->pressed = g_new0(uint8_t, s->num_buttons);
61 qdev_init_gpio_out(dev, s->irqs, s->num_buttons);
62 - qemu_input_handler_register(dev, &stellaris_gamepad_handler);
62 + s->hs = qemu_input_handler_register(dev, &stellaris_gamepad_handler);
63 +}
64 +
65 +static void stellaris_gamepad_unrealize(DeviceState *dev)
66 +{
67 + StellarisGamepad *s = STELLARIS_GAMEPAD(dev);
68 +
69 + g_clear_pointer(&s->irqs, g_free);
70 + g_clear_pointer(&s->pressed, g_free);
71 + g_clear_pointer(&s->hs, qemu_input_handler_unregister);
72 }
73
74 static void stellaris_gamepad_reset_enter(Object *obj, ResetType type)
@@ -81,6 +90,7 @@ static void stellaris_gamepad_class_init(ObjectClass *klass, const void *data)
90
91 rc->phases.enter = stellaris_gamepad_reset_enter;
92 dc->realize = stellaris_gamepad_realize;
93 + dc->unrealize = stellaris_gamepad_unrealize;
94 dc->vmsd = &vmstate_stellaris_gamepad;
95 device_class_set_props(dc, stellaris_gamepad_properties);
96 }
include/hw/input/stellaris_gamepad.h
+2
@@ -13,6 +13,7 @@
13
14 #include "hw/core/sysbus.h"
15 #include "qom/object.h"
16 +#include "ui/input.h"
17
18 /*
19 * QEMU interface:
@@ -28,6 +29,7 @@ OBJECT_DECLARE_SIMPLE_TYPE(StellarisGamepad, STELLARIS_GAMEPAD)
29 struct StellarisGamepad {
30 SysBusDevice parent_obj;
31
32 + QemuInputHandlerState *hs;
33 uint32_t num_buttons;
34 qemu_irq *irqs;
35 uint32_t *keycodes;