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>
This commit is contained in:
Marc-André Lureau
2026-06-09 01:10:33 +04:00
parent 6a935957d6
commit 4944ca9914
2 changed files with 13 additions and 1 deletions

View File

@@ -59,7 +59,16 @@ static void stellaris_gamepad_realize(DeviceState *dev, Error **errp)
s->irqs = g_new0(qemu_irq, s->num_buttons);
s->pressed = g_new0(uint8_t, s->num_buttons);
qdev_init_gpio_out(dev, s->irqs, s->num_buttons);
qemu_input_handler_register(dev, &stellaris_gamepad_handler);
s->hs = qemu_input_handler_register(dev, &stellaris_gamepad_handler);
}
static void stellaris_gamepad_unrealize(DeviceState *dev)
{
StellarisGamepad *s = STELLARIS_GAMEPAD(dev);
g_clear_pointer(&s->irqs, g_free);
g_clear_pointer(&s->pressed, g_free);
g_clear_pointer(&s->hs, qemu_input_handler_unregister);
}
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)
rc->phases.enter = stellaris_gamepad_reset_enter;
dc->realize = stellaris_gamepad_realize;
dc->unrealize = stellaris_gamepad_unrealize;
dc->vmsd = &vmstate_stellaris_gamepad;
device_class_set_props(dc, stellaris_gamepad_properties);
}

View File

@@ -13,6 +13,7 @@
#include "hw/core/sysbus.h"
#include "qom/object.h"
#include "ui/input.h"
/*
* QEMU interface:
@@ -28,6 +29,7 @@ OBJECT_DECLARE_SIMPLE_TYPE(StellarisGamepad, STELLARIS_GAMEPAD)
struct StellarisGamepad {
SysBusDevice parent_obj;
QemuInputHandlerState *hs;
uint32_t num_buttons;
qemu_irq *irqs;
uint32_t *keycodes;