From patchwork Tue Jun 27 16:09:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 696888 Delivered-To: patch@linaro.org Received: by 2002:adf:e885:0:0:0:0:0 with SMTP id d5csp3867978wrm; Tue, 27 Jun 2023 09:17:15 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7eZ+pNyvBztKOD9MkqQM62b/QE5iLBJfqj49KDZlhRlzTUTgO0gbNP30dh2nhRVq+PrWUK X-Received: by 2002:a05:6214:401a:b0:62f:f2fb:6915 with SMTP id kd26-20020a056214401a00b0062ff2fb6915mr33408212qvb.0.1687882634996; Tue, 27 Jun 2023 09:17:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687882634; cv=none; d=google.com; s=arc-20160816; b=vaSrgIeIk8N/40e8HHFUqC72JGuXwwI0FP95qpiLOLnQjLlhWBd6TjOIBi8C286QjM Kuo3mJiNjtTpocGoJPoWuuOx3XihASl4f+K0J7PD8g8M9zAyxD5u882TZJVbqwogzmDu AimHmbBV5RL8gB/hMPuWi/dvP3k0hnZfIVUR6qWe7ipvb3ce3reuDUKrXsicpojqPOMo /xyxNXIuD08INQYja3jBzGY+9XinsX4ubcNXyF32FXWDlo7kIOskhZZixoDs61S1h9c+ MxvAZvr5ZubXMIulaXuD5O+XiBYeTug9cb08LtbZPXUHsZcd2H+zye6vnt6B0ZHNQT5B VfUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=vvgukf2r/kz3Y+kIcG+gDWEsWDEFvjX8X24ODyGYeGY=; fh=ArV5Yx1z9lg+jufSSsiXTUg87d1rJ5PmrQDHLSB2i58=; b=AJ2Qcsj+83a2Fc0VqiNNq1YzNFVhW715NLIiipSQdL6w+D6M1r7w4hH3aIP5chETF5 ONu/WwmdUFO68xG09dtB7R1ZZ8IgXN+ihQf3FUJCVR4VAuzHv9+K4Qa4n/brAKFJRbPy sJOhDtcOJo+dhepr9gQuC6Kw63/BlkP2NNBwYVWxa7jeXCi2EvrxWAC7vWmNZ05fAJ2P V4GBfSQGcByhwue7PgAkKWAv74HCwV/wMPi/+x/yNW0fZraLT0OHQpALWXYQ5qnMSX6V XLh+HnapeNQx3aoveccCfIsWSIkFP52JNsvQDZTfQ3f9dqZQsh7CaCUuE5aj9idfVwMv c/OQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ErM9F2iw; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id o10-20020ad45c8a000000b00635e04171c4si2203797qvh.419.2023.06.27.09.17.14 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 27 Jun 2023 09:17:14 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ErM9F2iw; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qEBMN-0001BT-4z; Tue, 27 Jun 2023 12:16:07 -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 1qEBMI-00012z-MP for qemu-devel@nongnu.org; Tue, 27 Jun 2023 12:16:02 -0400 Received: from mail-lf1-x133.google.com ([2a00:1450:4864:20::133]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qEBMA-00088J-Gs for qemu-devel@nongnu.org; Tue, 27 Jun 2023 12:16:02 -0400 Received: by mail-lf1-x133.google.com with SMTP id 2adb3069b0e04-4f865f0e16cso6543638e87.3 for ; Tue, 27 Jun 2023 09:15:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1687882551; x=1690474551; 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=vvgukf2r/kz3Y+kIcG+gDWEsWDEFvjX8X24ODyGYeGY=; b=ErM9F2iwYIT4I5Wc99hl/3FeC3hQTqGEZZYKxHbe870Iyn6HivIDKLhWoQZb/XMu7M HsmmJ4I/dtEZtWkVLe/tAMkU6HQ4I42RWB5Se/TZQUXCNGd179pOZiQ9FRSqXKyLKqfW eZpXQnerd9kx88wLIp/SOLQ6F5XdXgCAmoqIVoLhLnopOeLCvmOg9Qmj+JiACikFbReA qPO2i9NMTcFjStxEJC/aveHuJO/yO27BbTDdXctcA9goIH8ZeA7IigeAy5jxIjN+mENh ueYLKtB1helOX5/ksEgRdWDiy7GjBM3pb9igtwDSMLNaMVzy1InDc5+TCIiAtRm35Kfg FsLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687882551; x=1690474551; 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=vvgukf2r/kz3Y+kIcG+gDWEsWDEFvjX8X24ODyGYeGY=; b=X6UUw4YrOqmu1zOz17d0ftnysn14yteESrA+qBiFqepjiyRp99Ens8DsooblTn1IlK 8HnoajCbCaAvnXeSN1xbkxdDmBbF7YsfoDJYzdqX37qrZNygAbSC7MlHOHd3/JXhIXAc 7I2QIlXARCmtIiyKiNetrOZhN5x3Fiyt4yA71rhCVOwPkSKx9ZKXwRdejDGek1o2pBNS rmF2gE2fbGxzQLWP3erMYRTZjv6SXrg/z9mLkqY6PtKacA7sEM+oA3aMs6otcdWdHaOd 8szjWoUAcGOCSBwzS4DBEZl7cwf+Pp8u3qyAQ7h184rudZ8saMi9UD5QapfWhMfDZwGT HYQg== X-Gm-Message-State: AC+VfDzfnytzaTYub4+YkqzE0rrp8n4/cxFpUMErY9x8mj31QMI+YUAY jpLpKy/xt/U7DzgVvaj3Y9dk9A== X-Received: by 2002:a19:c206:0:b0:4fa:3a0:2257 with SMTP id l6-20020a19c206000000b004fa03a02257mr5139619lfc.5.1687882551301; Tue, 27 Jun 2023 09:15:51 -0700 (PDT) Received: from zen.linaroharston ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id y12-20020a05600c364c00b003f7f249e7dfsm14308607wmq.4.2023.06.27.09.15.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Jun 2023 09:15:50 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 3AAB01FFC6; Tue, 27 Jun 2023 17:09:47 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Wainer dos Santos Moschetta , Juan Quintela , Thomas Huth , Cleber Rosa , Leonardo Bras , Beraldo Leal , Peter Maydell , Bin Meng , Yanan Wang , Darren Kenny , Alexander Bulekov , Marcel Apfelbaum , Peter Xu , Radoslaw Biernacki , Laurent Vivier , Paolo Bonzini , Eduardo Habkost , qemu-arm@nongnu.org, Stefan Hajnoczi , Richard Henderson , Bandan Das , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?Dani?= =?utf-8?q?el_P=2E_Berrang=C3=A9?= , Alexandre Iooss , Marcin Juszkiewicz , Leif Lindholm , Laurent Vivier , Qiuhao Li , Mahmoud Mandour , Riku Voipio , =?utf-8?q?Alex_Benn=C3=A9e?= Subject: [PATCH v3 28/36] gdbstub: clean-up vcont handling to avoid goto Date: Tue, 27 Jun 2023 17:09:35 +0100 Message-Id: <20230627160943.2956928-29-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230627160943.2956928-1-alex.bennee@linaro.org> References: <20230627160943.2956928-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::133; envelope-from=alex.bennee@linaro.org; helo=mail-lf1-x133.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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org 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ée Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Richard Henderson --- 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 = 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 = gdb_get_max_cpus(); /* uninitialised CPUs stay 0 */ - newstates = g_new0(char, max_cpus); + g_autofree char *newstates = g_new0(char, max_cpus); /* mark valid CPUs with 1 */ CPU_FOREACH(cpu) { @@ -597,8 +596,7 @@ static int gdb_handle_vcont(const char *p) res = 0; while (*p) { if (*p++ != ';') { - res = -ENOTSUP; - goto out; + return -ENOTSUP; } cur_action = *p++; @@ -606,13 +604,12 @@ static int gdb_handle_vcont(const char *p) cur_action = qemu_tolower(cur_action); res = qemu_strtoul(p, &p, 16, &tmp); if (res) { - goto out; + return res; } signal = gdb_signal_to_target(tmp); } else if (cur_action != 'c' && cur_action != 's') { /* unknown/invalid/unsupported command */ - res = -ENOTSUP; - goto out; + return -ENOTSUP; } if (*p == '\0' || *p == ';') { @@ -625,14 +622,12 @@ static int gdb_handle_vcont(const char *p) } else if (*p++ == ':') { kind = read_thread_id(p, &p, &pid, &tid); } else { - res = -ENOTSUP; - goto out; + return -ENOTSUP; } switch (kind) { case GDB_READ_THREAD_ERR: - res = -EINVAL; - goto out; + return -EINVAL; case GDB_ALL_PROCESSES: cpu = gdb_first_attached_cpu(); @@ -649,8 +644,7 @@ static int gdb_handle_vcont(const char *p) process = gdb_get_process(pid); if (!process->attached) { - res = -EINVAL; - goto out; + return -EINVAL; } cpu = get_first_cpu_in_process(process); @@ -668,8 +662,7 @@ static int gdb_handle_vcont(const char *p) /* invalid CPU/thread specified */ if (!cpu) { - res = -EINVAL; - goto out; + return -EINVAL; } /* only use if no previous match occourred */ @@ -679,12 +672,9 @@ static int gdb_handle_vcont(const char *p) break; } } + gdbserver_state.signal = signal; gdb_continue_partial(newstates); - -out: - g_free(newstates); - return res; }