From patchwork Tue Feb 27 18:48:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 776280 Delivered-To: patch@linaro.org Received: by 2002:adf:a113:0:b0:33d:f458:43ce with SMTP id o19csp308961wro; Tue, 27 Feb 2024 10:50:58 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCWE3S1pt4r2iDfelr7BRyzDnhN3lkNAq46eOoBDCbfAf5N0jfNK0E0UjgnTUNWKpWLrOX97hpWqp3UOrCFYAYS2 X-Google-Smtp-Source: AGHT+IG2dd91IARVvddZHEN9491lAHLbk59oagJ6iEUlnz48dte6RMugFj34gSTn00LMhQONwnau X-Received: by 2002:a05:6358:5713:b0:17b:759:65c2 with SMTP id a19-20020a056358571300b0017b075965c2mr14116829rwf.10.1709059858303; Tue, 27 Feb 2024 10:50:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709059858; cv=none; d=google.com; s=arc-20160816; b=KajDLjt1GjjhvIIoVL8j9LG+EaqVvDzCJOGC1vFaZ/JjTiEXnUfzCjVRtVcYc4FjVk 8OBJFt7BJ554MpdDEKa9mxkkRL9p9hWvR1Gn0LyomUy7iagLe/7fNEM2mlwsX3WHpf7I 5CG+nPaxQoHH9+5gZQKkwjTpHz+0HmnFtXbN0lqEVErANlytFWf3pMtm5sbS23qI79Q5 QjhKviIUmtvPun2L1CTCGCha4fYx4ELuxNP3XY83ct6Ssyq/rOvms3al1YVkfkQLGxI5 ohGcA95P4dTslc3k4t6AyGnkc/97tVUMzRzh6cuKOPKupvNfFh7T8k52cuhnNRNFHLVu rj0g== 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=0IQWSjcLXc40VTcQlmdhU2o876C5B7NqB15Y8LB3+3A=; fh=Vvliz9ENSk/yCY42nG87aL5dW+Zo0lduSx74U3lH2V8=; b=DY/P113B86y3I1TUWxdWtoLc+xxvmXfLTS9NYvxJ/yXaH17wgNqMbT2G73VSZqdDYI SoanqPt624Yr11Hknk52EwduVpfHG/1OSboYVkGPkaK01UDO1kC/R/xQeADMWi4pwbNl nCwqwzuG/XmZnUPjT4vhEIBH8GV3i4lt3ylxCwIwvC/dNGAy9Ur6681xmhAhrpEnwja5 FWHI8MPa+GUnYpyWCXSfzA/FN0N+X0jf0UQElgfigbO1L9CFPDyzTcl/pgkgwkb5dWf6 wvhN12FisfEBzeoXe8AX4FreBI8pT9C/RQppBHz7u9zgK5Le9NB+9T9aep79NqyAAFus Yp9Q==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=SaZFfP9r; 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 q14-20020a056214194e00b0068fb883d21bsi8056221qvk.271.2024.02.27.10.50.58 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 27 Feb 2024 10:50:58 -0800 (PST) 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=SaZFfP9r; 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 1rf2VT-0006X5-UJ; Tue, 27 Feb 2024 13:48:48 -0500 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 1rf2VS-0006WP-BW for qemu-devel@nongnu.org; Tue, 27 Feb 2024 13:48:46 -0500 Received: from mail-ot1-x32c.google.com ([2607:f8b0:4864:20::32c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rf2VQ-0001TX-VG for qemu-devel@nongnu.org; Tue, 27 Feb 2024 13:48:46 -0500 Received: by mail-ot1-x32c.google.com with SMTP id 46e09a7af769-6e445b4f80bso2587881a34.0 for ; Tue, 27 Feb 2024 10:48:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709059723; x=1709664523; darn=nongnu.org; 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=0IQWSjcLXc40VTcQlmdhU2o876C5B7NqB15Y8LB3+3A=; b=SaZFfP9rtg11C3ruHczOU9+wbj+9BQi/geWUqoL1W6ZJZT3Eupta3nxSXayim1Krpb roRxh8n9iUjlGiOyebxG24VzxjYYOlYJDPcqI2es0tLJsXcvT8+VOLkCT36B1LNt8lIX rjVRl24JRgigYlB4OMCP4WWoUHE0nVkX59Bvb0C4wCclav+99mw6Ea+jCl8GQL+/KR3g BFJ8lNZ1TccAGeefkyRLbieLTmd5EHvcqCnRbeNCS7z9mb2K1TzLdHPi0dsKJP+OWKjz USGbef61hRO0JDczE43pUYcg0W2EBROWpCmsijtreHA+CLMiAuJgm/VVrLQ8FOqhUUAw O67g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709059723; x=1709664523; 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=0IQWSjcLXc40VTcQlmdhU2o876C5B7NqB15Y8LB3+3A=; b=QNFg/Ky1TSVyzeNJ311HFDv1cfkz8+6GgL0T6VUTGetcA8AX58k1Yh0gzbzdwSIm4e vUZWSJKiWciP+xkr11Mv38Gi/tgu9AGOMhhSsAUuEUbuxuEG8xOB79I/nbs8cZrmGx2k j3pEC8Rsj5qvkKJaE8ukmk9vlXjA21+19MV7gbqSPYKIzMU8cs8NyolbPxqxKCcMgq1Y PW8p5HsS+qAObwephQ0Cuo27WUudr2wQRPE42vK6pRT6b3ChxpQg59QOaKHZLdQvTSkG f1ZjS8jF7RI79UnzHOP13e8P7Mkf+eNyICwLrXK5AxZWk3Bt2ghPqeyO596zN6eYBSiB C2MA== X-Gm-Message-State: AOJu0Yxi5KmwInBn8Iz06HjdZcPpOe58cJ/JU2EDcihNkB78AYTpyVyL U8sKQ7xiu21lz8yH/3tpbznHAEQ0RgxaFnXwPskIixbSVz20WaTmdF5Q5N8CA+P1Pl2n/4scl39 y X-Received: by 2002:a05:6870:700e:b0:21f:c705:7d8c with SMTP id u14-20020a056870700e00b0021fc7057d8cmr13325878oae.26.1709059723679; Tue, 27 Feb 2024 10:48:43 -0800 (PST) Received: from stoup.. (098-147-055-211.res.spectrum.com. [98.147.55.211]) by smtp.gmail.com with ESMTPSA id h26-20020aa786da000000b006e555d40951sm533465pfo.188.2024.02.27.10.48.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 10:48:43 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alex.bennee@linaro.org Subject: [PATCH 05/14] linux-user/elfload: Latch errno before cleanup in elf_core_dump Date: Tue, 27 Feb 2024 08:48:24 -1000 Message-Id: <20240227184833.193836-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240227184833.193836-1-richard.henderson@linaro.org> References: <20240227184833.193836-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::32c; envelope-from=richard.henderson@linaro.org; helo=mail-ot1-x32c.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 On the off-chance that one of the cleanup functions changes errno, latch the errno that we want to return beforehand. Flush errno to 0 upon success, rather than at the beginning. No need to avoid negation of 0. Signed-off-by: Richard Henderson --- linux-user/elfload.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 98b82b1a49..39d9ef9acc 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -4634,8 +4634,7 @@ static int elf_core_dump(int signr, const CPUArchState *env) off_t offset = 0, data_offset = 0; int segs = 0; int fd = -1; - - errno = 0; + int ret; if (prctl(PR_GET_DUMPABLE) == 0) { return 0; @@ -4755,15 +4754,14 @@ static int elf_core_dump(int signr, const CPUArchState *env) goto out; } } + errno = 0; out: + ret = -errno; free_note_info(&info); vma_delete(&mm); - (void) close(fd); - - if (errno != 0) - return (-errno); - return (0); + close(fd); + return ret; } #endif /* USE_ELF_CORE_DUMP */