parent_unrealize is NULL since neither ADBDeviceClass nor
DeviceClass sets dc->unrealize. Guard the call to prevent
a NULL dereference during device teardown.

Fixes: 6a935957d60e ("hw/input: keep QemuInputHandlerState in adb-kbd")
Signed-off-by: Marc-André Lureau <[email protected]>
---
 hw/input/adb-kbd.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/hw/input/adb-kbd.c b/hw/input/adb-kbd.c
index d4a131dc1295..43c0ead60c59 100644
--- a/hw/input/adb-kbd.c
+++ b/hw/input/adb-kbd.c
@@ -401,7 +401,9 @@ static void adb_kbd_unrealizefn(DeviceState *dev)
     ADBKeyboardClass *akc = ADB_KEYBOARD_GET_CLASS(dev);
 
     g_clear_pointer(&s->hs, qemu_input_handler_unregister);
-    akc->parent_unrealize(dev);
+    if (akc->parent_unrealize) {
+        akc->parent_unrealize(dev);
+    }
 }
 
 static void adb_kbd_initfn(Object *obj)

-- 
2.56.0.rc0.29.g47ce80527c56


Reply via email to