@samitouri / QOSamiQemu / commits / 6a935957d6

hw/input: keep QemuInputHandlerState in adb-kbd

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 6a935957d60ea03b616802f7e488359b473c665d
1 file changed +16 -1
hw/input/adb-kbd.c
+16 -1
@@ -40,6 +40,7 @@ struct KBDState {
40 ADBDevice parent_obj;
41 /*< public >*/
42
43 + QemuInputHandlerState *hs;
44 uint8_t data[128];
45 int rptr, wptr, count;
46 };
@@ -51,6 +52,7 @@ struct ADBKeyboardClass {
52 /*< public >*/
53
54 DeviceRealize parent_realize;
55 + DeviceUnrealize parent_unrealize;
56 };
57
58 /* The adb keyboard doesn't have every key imaginable */
@@ -361,9 +363,20 @@ static const QemuInputHandler adb_keyboard_handler = {
363
364 static void adb_kbd_realizefn(DeviceState *dev, Error **errp)
365 {
366 + KBDState *s = ADB_KEYBOARD(dev);
367 ADBKeyboardClass *akc = ADB_KEYBOARD_GET_CLASS(dev);
368 +
369 akc->parent_realize(dev, errp);
366 - qemu_input_handler_register(dev, &adb_keyboard_handler);
370 + s->hs = qemu_input_handler_register(dev, &adb_keyboard_handler);
371 +}
372 +
373 +static void adb_kbd_unrealizefn(DeviceState *dev)
374 +{
375 + KBDState *s = ADB_KEYBOARD(dev);
376 + ADBKeyboardClass *akc = ADB_KEYBOARD_GET_CLASS(dev);
377 +
378 + g_clear_pointer(&s->hs, qemu_input_handler_unregister);
379 + akc->parent_unrealize(dev);
380 }
381
382 static void adb_kbd_initfn(Object *obj)
@@ -381,6 +394,8 @@ static void adb_kbd_class_init(ObjectClass *oc, const void *data)
394
395 device_class_set_parent_realize(dc, adb_kbd_realizefn,
396 &akc->parent_realize);
397 + device_class_set_parent_unrealize(dc, adb_kbd_unrealizefn,
398 + &akc->parent_unrealize);
399 set_bit(DEVICE_CATEGORY_INPUT, dc->categories);
400
401 adc->devreq = adb_kbd_request;