adb_mouse_realizefn calls parent_realize but does not check for
errors before continuing. When the caller passes errp as NULL,
a failure is silently ignored and qemu_input_handler_register
runs on a device that failed to realize.

Use ERRP_GUARD() and check *errp to properly detect and
propagate errors regardless of the caller's errp value.

Fixes: 2e4a7c9c5df4 ("adb: QOM'ify ADB devices")
Signed-off-by: Marc-André Lureau <[email protected]>
---
 hw/input/adb-mouse.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/hw/input/adb-mouse.c b/hw/input/adb-mouse.c
index 80584cce1c6b..f9f989930ba1 100644
--- a/hw/input/adb-mouse.c
+++ b/hw/input/adb-mouse.c
@@ -25,6 +25,7 @@
 #include "qemu/osdep.h"
 #include "ui/console.h"
 #include "hw/input/adb.h"
+#include "qapi/error.h"
 #include "migration/vmstate.h"
 #include "qemu/module.h"
 #include "adb-internal.h"
@@ -274,7 +275,12 @@ static void adb_mouse_realizefn(DeviceState *dev, Error 
**errp)
     MouseState *s = ADB_MOUSE(dev);
     ADBMouseClass *amc = ADB_MOUSE_GET_CLASS(dev);
 
+    ERRP_GUARD();
+
     amc->parent_realize(dev, errp);
+    if (*errp) {
+        return;
+    }
 
     s->hs = qemu_input_handler_register(dev, &adb_mouse_handler);
 }

-- 
2.56.0.rc0.29.g47ce80527c56


Reply via email to