From a0506b7c8fc72f7bca272647f359d76cc40a02c1 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Mon, 9 Jan 2023 20:03:21 +0100 Subject: [PATCH] ui: Simplify control flow in qemu_mouse_set() MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Markus Armbruster Message-Id: <20230109190321.1056914-18-armbru@redhat.com> Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Daniel P. Berrangé --- ui/input.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/ui/input.c b/ui/input.c index 7048810a57..f2d1e7a3a7 100644 --- a/ui/input.c +++ b/ui/input.c @@ -595,28 +595,26 @@ MouseInfoList *qmp_query_mice(Error **errp) bool qemu_mouse_set(int index, Error **errp) { QemuInputHandlerState *s; - int found = 0; QTAILQ_FOREACH(s, &handlers, node) { - if (s->id != index) { - continue; - } - if (!(s->handler->mask & (INPUT_EVENT_MASK_REL | - INPUT_EVENT_MASK_ABS))) { - error_setg(errp, "Input device '%s' is not a mouse", - s->handler->name); - return false; + if (s->id == index) { + break; } - found = 1; - qemu_input_handler_activate(s); - break; } - if (!found) { + if (!s) { error_setg(errp, "Mouse at index '%d' not found", index); return false; } + if (!(s->handler->mask & (INPUT_EVENT_MASK_REL | + INPUT_EVENT_MASK_ABS))) { + error_setg(errp, "Input device '%s' is not a mouse", + s->handler->name); + return false; + } + + qemu_input_handler_activate(s); qemu_input_check_mode_change(); return true; } -- 2.11.4.GIT