From patchwork Fri Jun 30 18:04:15 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: 697970 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp596718wrs; Fri, 30 Jun 2023 11:14:16 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6+4okuwR01XOlx8GeY89IQdqxoKAdDzA3uvCnuXqF32Ge8gbO1YRMFGfY2ThqQIgEgRW4o X-Received: by 2002:ac8:5acf:0:b0:400:83a6:6e7 with SMTP id d15-20020ac85acf000000b0040083a606e7mr3982033qtd.67.1688148856284; Fri, 30 Jun 2023 11:14:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688148856; cv=none; d=google.com; s=arc-20160816; b=Rbpfqm8Kj+DYghBK4fFLV82cH5n2BRnM3X74UWVWvvq4u2V+NVLn/lOs+vDG4auU2R CNUhfEBLy+WCaTthRatMLR/kMp98b0NYi5G9R7mP82yRKEvtxDuvGHGvWm3WK1fvwWqq cYpH9vG+t6mbLXJvUE63zoHB84TfkduZMOc/uolEsTRTuW0Kolr9kBhaCRK2gmXIXasq hsebcXURaI1NGZ6j5AKP72QZ4HTg+A7ylgrXIcvgYgDAVbrZanWW59+gRAe40AMIIax5 LeqT6RHnuhAMg6xe8+a4zmnJE0ZpMrlut/C2s6ziPZ4199XTr7CTSWKT4Jd6yB7jmGTj jSbA== 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=noOnfZ3FZdhjlEdVG7JVDMqP/nuQCMSustvyazImnlo=; fh=OltHerz+Vf7zZkebZbScoRT4WgVwJDskRS7DoEjx2Hw=; b=E1gaFxt5ce1jhLTXoqimFIt1bzCbNvo79Z7xoeLMfY6UW3dmp/PpOa/e7WdvR4F3yF ebwjZtIm4sQRKncAlpDr+jcfj0kVksS2PMSwCOmoeaL5k6iRKaZKu6jOFhIC/SU5PIGt KEi9DBSUUiiw1jOwg61i10lJmc7h5GwHDW3ds5YKgS9nXjzt18ca8zsevW74b7gj+eoF uwcBy+nX9XbCipUCmFusobmhaf3G/WERB15iEqVsFd3QUJSt3QiytZNJaBdnuxVYszRZ TITjHIkvHOyPmQtUcWM4qeUFtvGDFh69PObJ3VWXeKs0gmRCuo3nkvBi8OhW2Y4a9aCY rBeA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=VI98akRw; 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 18-20020ac85912000000b003eaaed801a1si8336315qty.59.2023.06.30.11.14.16 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 30 Jun 2023 11:14:16 -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=VI98akRw; 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 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) 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-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) 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) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Daniel_P=2E_Berrang=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_Benn=C3=A9e?= , =?utf-8?q?Philippe_M?= =?utf-8?q?athieu-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 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+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. Message-Id: <20230627160943.2956928-29-alex.bennee@linaro.org> Reviewed-by: Richard Henderson Signed-off-by: Alex Bennée Reviewed-by: Philippe Mathieu-Daudé --- 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; }