From nobody Tue Nov 26 08:25:20 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1709059858; cv=none; d=zohomail.com; s=zohoarc; b=diI30w/DJpmL2uOu7482ynLFWauZVpYO7aPv4Fw6UI1cLklyzeY6BNbj76uQ65pVO33VpcO70GM2ma7XxxIfpFVehTvQNLhX3Utk189/xjxtPUKaq7NUPC5LoM5yvESFAsU7oUifKhnApCX2Knl288rk8R18Md5+qzqquPSu74A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709059858; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=0IQWSjcLXc40VTcQlmdhU2o876C5B7NqB15Y8LB3+3A=; b=msfTd5b0wXNpkTjH4qQ0oMBWlE+XJA0PV+l0a8fYF1Zs7pBBtOlP8heyRu31FIRl5iYoa0OWf7LBXuIH2BP1D6PLODTE/MFL3GEJ4WWHI9MX9vdcgOlKpDielSy2nhNhc1XYN/Li9LvsUe68tRuzmVEVMcDIfTfJ/sQy+seidh8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 17090598584523.6894543434469824; Tue, 27 Feb 2024 10:50:58 -0800 (PST) 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) 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) 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-Google-Smtp-Source: AGHT+IEyLVLD8uA5G6PJo6Aq97EcdNVif9Qz06281L7bF3lKNKunHKBbpGUimCpxu1FmLRAAzy88VA== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1709059859282100005 Content-Type: text/plain; charset="utf-8" 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 CPUArchStat= e *env) off_t offset =3D 0, data_offset =3D 0; int segs =3D 0; int fd =3D -1; - - errno =3D 0; + int ret; =20 if (prctl(PR_GET_DUMPABLE) =3D=3D 0) { return 0; @@ -4755,15 +4754,14 @@ static int elf_core_dump(int signr, const CPUArchSt= ate *env) goto out; } } + errno =3D 0; =20 out: + ret =3D -errno; free_note_info(&info); vma_delete(&mm); - (void) close(fd); - - if (errno !=3D 0) - return (-errno); - return (0); + close(fd); + return ret; } #endif /* USE_ELF_CORE_DUMP */ =20 --=20 2.34.1