From patchwork Mon Mar 11 19:12:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 779420 Delivered-To: patch@linaro.org Received: by 2002:a5d:604e:0:b0:33e:7753:30bd with SMTP id j14csp1686898wrt; Mon, 11 Mar 2024 12:13:35 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWef9krE9I9Oeku6h30EazKDK3vWs9n4TCVublS9ibtiVVWE7OL8Sr76/TXx3tGvz/ZjHu5uG6X19rNbDoUP2UV X-Google-Smtp-Source: AGHT+IF9envZJ+ct+udiJr8ba+8dAu8K73FyM93Qei9FM6i1yxLQPFiYQqDtEWPiA+NII/+4uJM+ X-Received: by 2002:a05:620a:40c9:b0:788:799f:d8bc with SMTP id g9-20020a05620a40c900b00788799fd8bcmr162811qko.0.1710184415375; Mon, 11 Mar 2024 12:13:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1710184415; cv=none; d=google.com; s=arc-20160816; b=LsxgN19kyuPfraRZrpyOjQC9ClT0qua9K6foCEgc46MhC+zUINrEDlcvYaPk6ngX80 PasFT18W5ntncX3XkN+cjlSfvVkJwGgqGweM+1p0kbrr6zaefDiVfOUB+d6DEF3X3M8j p4MgQD/71hQ/Io/ymJqpqPehq0EEKAbiGUb4wwA6rTE36bbqnVjGs4DAJO+BKj1ib2i0 lGRNKGmphqCuvdoJQzP9oLQNsjd8QZua/ub2O7Tvn7gjQqz2npEGmIHekdkunf5XKfEW vKLYRDfrSUMYpaH8u2pqg71Iv2jVjkCxdJVG/H9xrYHpDKfSDeesIj1xGxAhM0IbMzw/ Wr/g== 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:to:from :dkim-signature; bh=cG+mNjXKngqOkSeG7u+wCX4BlFv1Veow5VunaRM/YT4=; fh=PnYt+qEB9tAfMKoqBm2xjKOFpYyFFGPudh5cVIoieJM=; b=l57FI5B91RRyWo0fhbJQA+eYJ1ovPg8+s1mrLV7ICMn/2jeusAhRuZUudFb1MBKHde sSCHJCKow5M3gcKYwENpWj3aY2RMaZ2ERchSUEH1Oeri42J6mYxXolRt6glJW+8iKXXE 5VPWiEDmvdsvMnfez/401mY+kfRohX75g+4NFfKBO6F6UR2fTxg8RXejqp2/qD0R7Jjr nQIXjVqDtOVKx7vPOpeiV88RxOePuLTk6ECoVdxmh+m6U7icAo3oMNHmnXxd/7QmHd2E JXi7tT9CksYU9aQhsnkH2HQxBNOHb6OefCmeIZ/nJ3My9joP1AWH8JHFaCtbeXVC0w5y UoaA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=mGTiREYi; 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 wg25-20020a05620a569900b00787330d0232si5736343qkn.485.2024.03.11.12.13.35 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 11 Mar 2024 12:13:35 -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=mGTiREYi; 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 1rjl5K-0003TP-Fw; Mon, 11 Mar 2024 15:13:20 -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 1rjl4q-0003IZ-Oe for qemu-devel@nongnu.org; Mon, 11 Mar 2024 15:12:51 -0400 Received: from mail-lf1-x131.google.com ([2a00:1450:4864:20::131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rjl4n-0000Lx-MC for qemu-devel@nongnu.org; Mon, 11 Mar 2024 15:12:48 -0400 Received: by mail-lf1-x131.google.com with SMTP id 2adb3069b0e04-513af1a29b1so1089744e87.1 for ; Mon, 11 Mar 2024 12:12:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1710184364; x=1710789164; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=cG+mNjXKngqOkSeG7u+wCX4BlFv1Veow5VunaRM/YT4=; b=mGTiREYibluVYg94H8xMB3Z2/9Wwic4qVJYHSoZ4IT2XGSLO3euNHmBrZAASwgq8DF b70MayJBvB/IZGnTTsNd8d88X/ae5eO4J6Nol9fDie43TaRzdc+189N7QYRDfsLS9fCK VpDP07ANiOHtKtqPxPdigocJD9Wdkp4PuQ/I5CToNaLkvc8r2qv/sQZq5ZUp0+1wytN4 HBz1s/yxcnv7OZwBc0tTBQg/jSZVFVXjhdkHxkBJNZ9SfVV9gS/6vWpnW+QlIdWCjeSS fGj4lJ/kU/ouvFxD8+2N992AzSqSjr1cEHiV+YF6GN6k8Sbm9+7Vp4trEcEieTHQLrSc 8xZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710184364; x=1710789164; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=cG+mNjXKngqOkSeG7u+wCX4BlFv1Veow5VunaRM/YT4=; b=BRoZjsTuqf3C1+4RHBriLPpqQz8mm2UnJaSgkvycw+YcbeRirkveuTXE3CIb4dMSHf BZWvw3c8xv5oebdIWHdfeqNrdY+179BYkPtTKRIXbjXWdG/znLRLBiIGjeJmhO2zgOqy r7C109gbp4TViX8Mfsw8JYBslhj9yeT1XBHxy4iYYmsP0Tp5ae5DsOrMQXH0/6wl5y/f nzVKuXMckm2EDV73jNQR9a3xGr0t6QxTRxvegqRKUgyQD5aBX6ElplFazfo2dEHvUmta aG2Yxwq3ia+q4Q/P7xfjF0nWn7x1Zc/etJGIxxbyPSND+VonBR62obGaG2ooSXnZI051 sBMw== X-Gm-Message-State: AOJu0Yxttk/jMBv1/3dh52Leg4EFKgEalJTI7O3qzI/0zHh5Eg3rKWAs J4KA9pZIfP3/tF1Y1ToIz+UaGzgtgbOUxz7ATt3uuHjUZt6sUTAqK8WKqM8vae+EvqBETBJTaWs S X-Received: by 2002:a19:3807:0:b0:513:8f53:cab0 with SMTP id f7-20020a193807000000b005138f53cab0mr5061837lfa.27.1710184363768; Mon, 11 Mar 2024 12:12:43 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id t10-20020a05600c450a00b004131388d948sm14425266wmo.0.2024.03.11.12.12.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Mar 2024 12:12:43 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 03/20] contrib/elf2dmp: Assume error by default Date: Mon, 11 Mar 2024 19:12:24 +0000 Message-Id: <20240311191241.4177990-4-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240311191241.4177990-1-peter.maydell@linaro.org> References: <20240311191241.4177990-1-peter.maydell@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::131; envelope-from=peter.maydell@linaro.org; helo=mail-lf1-x131.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 From: Akihiko Odaki A common construct in contrib/elf2dmp is to set "err" flag and goto in error paths. In such a construct, there is only one successful path while there are several error paths, so it will be more simpler to initialize "err" flag set, and clear it in the successful path. Signed-off-by: Akihiko Odaki Reviewed-by: Peter Maydell Tested-by: Viktor Prutyanov Message-id: 20240307-elf2dmp-v4-2-4f324ad4d99d@daynix.com Signed-off-by: Peter Maydell --- contrib/elf2dmp/download.c | 4 +--- contrib/elf2dmp/main.c | 15 +++------------ 2 files changed, 4 insertions(+), 15 deletions(-) diff --git a/contrib/elf2dmp/download.c b/contrib/elf2dmp/download.c index bd7650a7a27..902dc04ffa5 100644 --- a/contrib/elf2dmp/download.c +++ b/contrib/elf2dmp/download.c @@ -11,7 +11,7 @@ int download_url(const char *name, const char *url) { - int err = 0; + int err = 1; FILE *file; CURL *curl = curl_easy_init(); @@ -21,7 +21,6 @@ int download_url(const char *name, const char *url) file = fopen(name, "wb"); if (!file) { - err = 1; goto out_curl; } @@ -33,7 +32,6 @@ int download_url(const char *name, const char *url) || curl_easy_perform(curl) != CURLE_OK) { unlink(name); fclose(file); - err = 1; } else { err = fclose(file); } diff --git a/contrib/elf2dmp/main.c b/contrib/elf2dmp/main.c index cbc38a7c103..9b278f392e3 100644 --- a/contrib/elf2dmp/main.c +++ b/contrib/elf2dmp/main.c @@ -511,7 +511,7 @@ static void pe_get_pdb_symstore_hash(OMFSignatureRSDS *rsds, char *hash) int main(int argc, char *argv[]) { - int err = 0; + int err = 1; QEMU_Elf qemu_elf; struct pa_space ps; struct va_space vs; @@ -542,7 +542,6 @@ int main(int argc, char *argv[]) if (pa_space_create(&ps, &qemu_elf)) { eprintf("Failed to initialize physical address space\n"); - err = 1; goto out_elf; } @@ -552,7 +551,6 @@ int main(int argc, char *argv[]) va_space_create(&vs, &ps, state->cr[3]); if (fix_dtb(&vs, &qemu_elf)) { eprintf("Failed to find paging base\n"); - err = 1; goto out_elf; } @@ -561,7 +559,6 @@ int main(int argc, char *argv[]) if (va_space_rw(&vs, state->idt.base, &first_idt_desc, sizeof(first_idt_desc), 0)) { eprintf("Failed to get CPU #0 IDT[0]\n"); - err = 1; goto out_ps; } printf("CPU #0 IDT[0] -> 0x%016"PRIx64"\n", idt_desc_addr(first_idt_desc)); @@ -586,7 +583,6 @@ int main(int argc, char *argv[]) if (!kernel_found) { eprintf("Failed to find NT kernel image\n"); - err = 1; goto out_ps; } @@ -600,45 +596,40 @@ int main(int argc, char *argv[]) if (download_url(PDB_NAME, pdb_url)) { eprintf("Failed to download PDB file\n"); - err = 1; goto out_ps; } if (pdb_init_from_file(PDB_NAME, &pdb)) { eprintf("Failed to initialize PDB reader\n"); - err = 1; goto out_pdb_file; } if (!SYM_RESOLVE(KernBase, &pdb, KdDebuggerDataBlock) || !SYM_RESOLVE(KernBase, &pdb, KdVersionBlock)) { - err = 1; goto out_pdb; } kdbg = get_kdbg(KernBase, &pdb, &vs, KdDebuggerDataBlock); if (!kdbg) { - err = 1; goto out_pdb; } if (fill_header(&header, &ps, &vs, KdDebuggerDataBlock, kdbg, KdVersionBlock, qemu_elf.state_nr)) { - err = 1; goto out_kdbg; } if (fill_context(kdbg, &vs, &qemu_elf)) { - err = 1; goto out_kdbg; } if (write_dump(&ps, &header, argv[2])) { eprintf("Failed to save dump\n"); - err = 1; goto out_kdbg; } + err = 0; + out_kdbg: g_free(kdbg); out_pdb: