From nobody Wed Feb 11 02:08:36 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1687864045; cv=none; d=zohomail.com; s=zohoarc; b=SCOW5i7UNLDGAqrNqZ7d0TmVg4Mb5SXCgCRBknbviXA1lY+BncBKL+dYKtmIksIE6ysnKsT8iKbOf+BbNM3I5wQt00kcYDkwCj0B2stlj2rj8pWaxRqsxll0EZd7svEy6+SMSmeshy8Sc3JBmZY/6waSzOmhl48NxUWFLJkLPSs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1687864045; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=7NEGw3MmnLBEc4mR4nWzFGOUShsvbkyyXww1ZRv5cX8=; b=llHton4DZuDdOHvd0YUggWSsEqFswkM/+fACLEjOf7vDSORIZUuIjLl2h2edKErUG7E+5bganDFnNhHicPUV935TPTDZl94GDsaQp4EDmqtiQQMtZeCUkVXHEo/Du76roEOiGLnndBV9AspuHilZBBBoQHHTmAbluhio8iWQ0jA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1687864045866236.51019233918407; Tue, 27 Jun 2023 04:07:25 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qE6WW-00060d-PE; Tue, 27 Jun 2023 07:06:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qE6WV-00060F-Lb for qemu-devel@nongnu.org; Tue, 27 Jun 2023 07:06:15 -0400 Received: from mail-wr1-x431.google.com ([2a00:1450:4864:20::431]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qE6WT-0002Nd-Dp for qemu-devel@nongnu.org; Tue, 27 Jun 2023 07:06:15 -0400 Received: by mail-wr1-x431.google.com with SMTP id ffacd0b85a97d-3112f256941so3970621f8f.1 for ; Tue, 27 Jun 2023 04:06:02 -0700 (PDT) Received: from zen.linaroharston ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id u12-20020adfdd4c000000b0030903d44dbcsm10152261wrm.33.2023.06.27.04.06.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Jun 2023 04:06:00 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id AA09B1FFBB; Tue, 27 Jun 2023 12:05:59 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1687863960; x=1690455960; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=7NEGw3MmnLBEc4mR4nWzFGOUShsvbkyyXww1ZRv5cX8=; b=LJa+hZNSoL3v4QS/ymLRzswq8+iPvostUBzYICz/WQIcGbGVHBnNpyosMsIh5xkHdN grHuhg7V4CqdUGdWRfS9sfIiGBtnpGNOeoUOyNmaJ4DsHemUndklcT3rq36KhDJJDbku +Y7zAHEmaPzKcSrau/2Jcb1NpxobDH2RbOCuRVhQoHthTME9Di1O5/46vIPz4AVmnvDr JhHRPAUDtOEjB7DVB3PY8vKXG8jX5az1iR2URA17/OcfTF4FVBAD3z8K8ixB9f4EXnp0 hLWPa5KaQP0kb+BoQpY4Z6rC61gbd2976sb1pZDxc+CxuIJPAaRDh/PvdPEnVMPzFkv3 umKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687863960; x=1690455960; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=7NEGw3MmnLBEc4mR4nWzFGOUShsvbkyyXww1ZRv5cX8=; b=SlOqYBaRIPajYTYqRZOC0XvYguwy+bGnJ4GjZuVj/FUPXvCFrKGJa3J+W7MHUgMIfc eT2lGXG3RXayhY7eZ/cMrLCUDxfGByfF/PDU7Vxyr/jZ2SV5rITn75hhfsVZnnrxDf0o /1c4QAZJ4t6xGKBvwvzo/3fTxyt5N0R343N5z/lZ35pB5PakFo1dAP2lWJuUmpVtDRY2 QtDZJOnYB+Z4/1pUJ2xSdpufrvnTVOwpp8XRkh207aO4YL2alEoJO1uPFzKMillKoj1G Q3E/N3tOogbtiqbmbWrjI7J6aBQRL155QjwUu3kboFX2vwWZqJm31gcZfLcRDMdJGxHy GGaw== X-Gm-Message-State: AC+VfDylyGBzYDoJxp6of1WzLHsqaKJEOxaz/FmmOeKguTMFd3Hxd+Vz CImUD/YjDGy2PBhc2cY2E/Yu+A== X-Google-Smtp-Source: ACHHUZ5HMV006CE2N413OQd1ovR6huTKJUPqhe6ZO8FPvRQZ3zSB8FhzToqebAruRw8AVSoUVbNP7g== X-Received: by 2002:a5d:4447:0:b0:313:fd26:6ff4 with SMTP id x7-20020a5d4447000000b00313fd266ff4mr1447217wrr.23.1687863960486; Tue, 27 Jun 2023 04:06:00 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [RFC PATCH] gdbstub: clean-up vcont handling to avoid goto Date: Tue, 27 Jun 2023 12:05:53 +0100 Message-Id: <20230627110553.2697758-1-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::431; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x431.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1687864047183100002 We can handle all the error exit cases by using g_autofree() for the one thing that needs cleaning up on the exit. Signed-off-by: Alex Benn=C3=A9e Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- gdbstub/gdbstub.c | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/gdbstub/gdbstub.c b/gdbstub/gdbstub.c index 9496d7b175..49143c7d83 100644 --- a/gdbstub/gdbstub.c +++ b/gdbstub/gdbstub.c @@ -573,7 +573,6 @@ static int gdb_handle_vcont(const char *p) { int res, signal =3D 0; char cur_action; - char *newstates; unsigned long tmp; uint32_t pid, tid; GDBProcess *process; @@ -581,7 +580,7 @@ static int gdb_handle_vcont(const char *p) GDBThreadIdKind kind; unsigned int max_cpus =3D gdb_get_max_cpus(); /* uninitialised CPUs stay 0 */ - newstates =3D g_new0(char, max_cpus); + g_autofree char *newstates =3D g_new0(char, max_cpus); =20 /* mark valid CPUs with 1 */ CPU_FOREACH(cpu) { @@ -597,8 +596,7 @@ static int gdb_handle_vcont(const char *p) res =3D 0; while (*p) { if (*p++ !=3D ';') { - res =3D -ENOTSUP; - goto out; + return -ENOTSUP; } =20 cur_action =3D *p++; @@ -606,13 +604,12 @@ static int gdb_handle_vcont(const char *p) cur_action =3D qemu_tolower(cur_action); res =3D qemu_strtoul(p, &p, 16, &tmp); if (res) { - goto out; + return res; } signal =3D gdb_signal_to_target(tmp); } else if (cur_action !=3D 'c' && cur_action !=3D 's') { /* unknown/invalid/unsupported command */ - res =3D -ENOTSUP; - goto out; + return -ENOTSUP; } =20 if (*p =3D=3D '\0' || *p =3D=3D ';') { @@ -625,14 +622,12 @@ static int gdb_handle_vcont(const char *p) } else if (*p++ =3D=3D ':') { kind =3D read_thread_id(p, &p, &pid, &tid); } else { - res =3D -ENOTSUP; - goto out; + return -ENOTSUP; } =20 switch (kind) { case GDB_READ_THREAD_ERR: - res =3D -EINVAL; - goto out; + return -EINVAL; =20 case GDB_ALL_PROCESSES: cpu =3D gdb_first_attached_cpu(); @@ -649,8 +644,7 @@ static int gdb_handle_vcont(const char *p) process =3D gdb_get_process(pid); =20 if (!process->attached) { - res =3D -EINVAL; - goto out; + return -EINVAL; } =20 cpu =3D get_first_cpu_in_process(process); @@ -668,8 +662,7 @@ static int gdb_handle_vcont(const char *p) =20 /* invalid CPU/thread specified */ if (!cpu) { - res =3D -EINVAL; - goto out; + return -EINVAL; } =20 /* only use if no previous match occourred */ @@ -679,12 +672,9 @@ static int gdb_handle_vcont(const char *p) break; } } + gdbserver_state.signal =3D signal; gdb_continue_partial(newstates); - -out: - g_free(newstates); - return res; } =20 --=20 2.39.2