From patchwork Mon Jul 3 13:44:19 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: 698710 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp1763007wrs; Mon, 3 Jul 2023 06:55:23 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7Kzz1k0jLX8W3m0KCroT0bBV1ORhr+PNmQtvuRjOOfStGISQKGiQpgz2GtiRb3dAcludHg X-Received: by 2002:ac8:5c10:0:b0:400:82b1:ad05 with SMTP id i16-20020ac85c10000000b0040082b1ad05mr18732703qti.7.1688392523536; Mon, 03 Jul 2023 06:55:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688392523; cv=none; d=google.com; s=arc-20160816; b=Yq+GEvMfRycUjfp1nckshgkKGBrsfuDripKEUJOXceu6TvguP3DZEGW34IO2+ygDc1 cWOQKBX3R2NfAQ8tUsBeWFc0XpQWIn/lS0NB+dQwGGkON9DDK74huRaWACaoDhyQ+Ws6 IaUx/hLIAfF5rG7AMqyRKibkFkdadewWCBj/yqdo5JqyozRmVDDxfB9eQh4crTyM/xOY AnxB6OcNxdIv9s2BKrxZ4Jcb3TInbfk6s7RZquakqjmGTDpcccF0b/oWuHRPQb3VQHg2 MLIPAYAP92S4E6S0HmKvCx5Rr1sZ5Bf1PVPiW1yrtvmQDtrHf3Ly0Mf8xK3p5fynwSkk SNEw== 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=zNMPVNXEa7UqeTcFlr3/SM98KrOm4fYZhU+BaBqT8mY=; fh=rFIn06eHzsx0Ek45moioqGE6M4mnjlt+HAXgA4erE9I=; b=SECgQnRqZhweauMhV0pCyj7cHPyno62Eq07lk0W1iTPIto+6KT30jguJ1EaeZU9AUV cfSIDYhe55I9NA4IV0O/GDGZZikT/lxeH6FyVHpvQuyztClIbJfh/duj0uZ8qWLO+9Q7 40gResef3KcIXClzLXZlz6zuLQFzlK1NblrODc+cE879EN8SRxraQmhZJfekCzqKMwMN BvXQu3axRRByk+0JAjqn+p76Bct5AK7qfbHreEp3WZrw5Y1+3ZylB1bYxtgqjHyWehjU 1KqWEdazzsU0oxSi7yRCJqDPQ0OvVBFhdpB+YhRfrofbeG2QP/9kFZ0KEwa3MxumkbUD XWuA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=uV9ZPLS8; 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 k9-20020a05622a03c900b003f502461662si11934211qtx.421.2023.07.03.06.55.23 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 03 Jul 2023 06:55:23 -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=uV9ZPLS8; 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 1qGJzp-0000bX-Gr; Mon, 03 Jul 2023 09:53:41 -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 1qGJzj-0000YA-B8 for qemu-devel@nongnu.org; Mon, 03 Jul 2023 09:53:35 -0400 Received: from mail-wr1-x42c.google.com ([2a00:1450:4864:20::42c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qGJzh-00082s-38 for qemu-devel@nongnu.org; Mon, 03 Jul 2023 09:53:35 -0400 Received: by mail-wr1-x42c.google.com with SMTP id ffacd0b85a97d-314172bb818so5153877f8f.1 for ; Mon, 03 Jul 2023 06:53:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688392411; x=1690984411; 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=zNMPVNXEa7UqeTcFlr3/SM98KrOm4fYZhU+BaBqT8mY=; b=uV9ZPLS81d0MTVEY2cXnk2V+85sjXaItitw7BNEe0vITv33afOl6HFjqmyV8LC912u 8J4ONws8InNEoZ7jXMdLonNXnd/ledyMXbioCq8y0G5DWrlWheBJJRuu2pK/JS4DJWpm 8jMEHcH9F4ekDUddaTIVCA8o5mZ7xzZg/6hMs2dtAKg/xpqIzMSI/YWAytml6gabZ64L eqhI+rlYq6KFU7fzwMZnRFKewmNijj0IIaivjJQUrqLX1U7EmvzIvtGtd4o68ECNgCR1 p4HRyC1ChOiYd1uDWlzBsMGcsbT8ULupwp+Oa/GzaS0VVHcozwwUNyenlDr3p5YGdzZ8 YnzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688392411; x=1690984411; 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=zNMPVNXEa7UqeTcFlr3/SM98KrOm4fYZhU+BaBqT8mY=; b=h+rHrX64cfAc49CBY3PoEEMqKU7utLxpm0dvz63CRafADD4Kv9a5Lh5FosmkdIQZXT N4xJ75yxAqL9RP0b+E9pH+UdBLbwHAiJBETVkKxGNGXnXNw+D7TSmOzXk/Zb/6gq5Nzw z6XdaqId8n7E0Zs49EAj7shU1dtTF68p3fd+kKOjwmmif4E93jL4m0h/hNDuMz3hGpep mhB/kcDyZ/8zp0cPlFEwCto5lOwwB3Yd3wXKy7ya4R+JUvEREaD2XrEbgsJRxX0X8Cnz kRfJAXe/C3OpVEeEnI8yK4qIfGEjNarorRyXb9ztqP32LVQwRXUyfQtKWHp5yPEuhQBx 5zeA== X-Gm-Message-State: ABy/qLaooFA2dQwfdI9KMl6SCHQEKgznEJBNFwwtrmbNXJC6Wi23lRFS PSID28BWL1YLhxBGEwz8huKPIA== X-Received: by 2002:adf:fc08:0:b0:314:824:378c with SMTP id i8-20020adffc08000000b003140824378cmr8597854wrr.20.1688392411749; Mon, 03 Jul 2023 06:53:31 -0700 (PDT) Received: from zen.linaroharston ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id w10-20020adfcd0a000000b003141f96ed36sm9420092wrm.0.2023.07.03.06.53.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Jul 2023 06:53:29 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 49DB21FFC1; Mon, 3 Jul 2023 14:44:31 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: richard.henderson@linaro.org, =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Philippe_M?= =?utf-8?q?athieu-Daud=C3=A9?= Subject: [PULL 30/38] gdbstub: clean-up vcont handling to avoid goto Date: Mon, 3 Jul 2023 14:44:19 +0100 Message-Id: <20230703134427.1389440-31-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230703134427.1389440-1-alex.bennee@linaro.org> References: <20230703134427.1389440-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42c; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x42c.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+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. Reviewed-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Alex Bennée Message-Id: <20230630180423.558337-31-alex.bennee@linaro.org> 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; }