From nobody Tue Feb 10 12:43:19 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=1688148856; cv=none; d=zohomail.com; s=zohoarc; b=PyQIdP8ME9c6o73BBDonH42yllLOm7eUpck8Thm/Cjc4xOHEYPPJQ3i6RwD8Sv+hZPh8G6VY0nPz4GY6cowmz0OOtiMWoeYDRF5AedvKZvudY7fc2F4nLVrEt3/PY/g6ZWpHKOvp1hze0K0MdRGOYBoBvXIJnUY0UvuRon7y3XU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1688148856; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=noOnfZ3FZdhjlEdVG7JVDMqP/nuQCMSustvyazImnlo=; b=YMwVy82Jt8WfdNaohtkmPK8rXwC1V3WnJlwrY5c5BD/WI7ccna9P8NjuJwuPmq6D7nCeaJ8xs7Txmn/fUuLNNe3RvWN99BSdyVIwQNn9DZFpdGGVYqEmbqh0f0V7yaUh+39T/ooUOXc6qV1yetkm5UcW7vI7W6579NWwCSX0JVs= 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 1688148856492632.4703563765612; Fri, 30 Jun 2023 11:14:16 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qFIcg-0005Na-Ry; Fri, 30 Jun 2023 14:13:34 -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 1qFIcf-0005MZ-5C for qemu-devel@nongnu.org; Fri, 30 Jun 2023 14:13:33 -0400 Received: from mail-wm1-x32b.google.com ([2a00:1450:4864:20::32b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qFIcb-0003VM-Rh for qemu-devel@nongnu.org; Fri, 30 Jun 2023 14:13:32 -0400 Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-3fbc6ab5ff5so11409535e9.1 for ; Fri, 30 Jun 2023 11:13:29 -0700 (PDT) Received: from zen.linaroharston ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id l21-20020a7bc455000000b003fa95c466a1sm15232380wmi.5.2023.06.30.11.13.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Jun 2023 11:13:27 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 696FD1FFD5; Fri, 30 Jun 2023 19:04:27 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688148808; x=1690740808; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=noOnfZ3FZdhjlEdVG7JVDMqP/nuQCMSustvyazImnlo=; b=VI98akRwt+XRNJczc8Rm7Mri7D3wdEaxHfy4i2FpSwkGWFOT8c9z4uJY0nCScc+yTL 8nt47fOni/djJJkt9WHOTT38BjH1v7A+MSafLkL3bX2Z4ZGdT43Z4muuu8D8jKRH6zSF +Mx8TUE8OIw7JhgUASMh4ni3Iwr/i+b6B5pxL6YV6BjOAW9NzWCKHnzRXN+TBIiEa9eg NzgeMCiAhVetkSluWlUv4mVJfL2m4SWloAtFylnE+EKQnyt5/mptFgj+KJYbvKdrjrTv 6ElS6LNDloaGwnd1h86THJvP5+25SrlDQBRpuzndP8YHXtd9dkzdIO0fZ7XB+P0dpcYO 1/mg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688148808; x=1690740808; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=noOnfZ3FZdhjlEdVG7JVDMqP/nuQCMSustvyazImnlo=; b=cjni8wDgvSjUyHXVZQrrDBvxfoMoDwuoRr3kULq90a53rUxKf5pSr7sepTc2Wj0Utc XkXiAQbbmtvOLgsGNnW0yn/MTBf9bb2+HIHEAF2ZtZsH12AFuhjr64tSl0h/RIKwok6B hmw0yTfLZKCk8tsbDS8oImS7rzE2euZauRtxwSPX3Bn5Rh6jbPldosm+IjoR9qYFluVp dTsDl1+Szuaw1YqsDKWOOWyBJoWeAapBTJ4e15YP5ivcARJ+dLMwkZaWGPProSPBXJpv Z8+2PKNbPNYQggK9WpSJtzzD3bNR/0/l4X5GxAw+v8t8oUgFH0AvTsaO27MbUgB5lbxs x/sg== X-Gm-Message-State: AC+VfDwws34sHCaiW8lToibj8qjZ2k5xzskWP60RgVAdQGZTKQdnDXpe bZuNQk92Dv+3+ARlZos2CSMhzg== X-Google-Smtp-Source: ACHHUZ48XT9nFT8Wj8row2H1nw673vwJncEMDp6jKdT6UW9ER2k5PEpNi5PrfLHFIpvdfZTVTw7VGg== X-Received: by 2002:a05:600c:b52:b0:3fb:afc0:56c5 with SMTP id k18-20020a05600c0b5200b003fbafc056c5mr2699745wmr.12.1688148807936; Fri, 30 Jun 2023 11:13:27 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Paolo Bonzini , Stefan Hajnoczi , Leonardo Bras , Laurent Vivier , Peter Xu , Juan Quintela , Beraldo Leal , Radoslaw Biernacki , Qiuhao Li , Peter Maydell , Yanan Wang , Riku Voipio , Wainer dos Santos Moschetta , Mahmoud Mandour , Alexandre Iooss , =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Eduardo Habkost , Thomas Huth , Laurent Vivier , Bin Meng , Marcel Apfelbaum , Bandan Das , Cleber Rosa , Richard Henderson , Leif Lindholm , Marcin Juszkiewicz , qemu-arm@nongnu.org, Darren Kenny , Alexander Bulekov Subject: [PATCH v4 30/38] gdbstub: clean-up vcont handling to avoid goto Date: Fri, 30 Jun 2023 19:04:15 +0100 Message-Id: <20230630180423.558337-31-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230630180423.558337-1-alex.bennee@linaro.org> References: <20230630180423.558337-1-alex.bennee@linaro.org> 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::32b; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x32b.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=unavailable 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: 1688148857678100012 We can handle all the error exit cases by using g_autofree() for the one thing that needs cleaning up on the exit. Message-Id: <20230627160943.2956928-29-alex.bennee@linaro.org> Reviewed-by: Richard Henderson 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