From patchwork Wed Jun 15 13:20:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Simek X-Patchwork-Id: 1643744 X-Patchwork-Delegate: monstr@monstr.eu Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=monstr-eu.20210112.gappssmtp.com header.i=@monstr-eu.20210112.gappssmtp.com header.a=rsa-sha256 header.s=20210112 header.b=SMiFp01k; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LNQts0mrpz9tlf for ; Wed, 15 Jun 2022 23:21:39 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 460228425F; Wed, 15 Jun 2022 15:21:32 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=monstr.eu Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=monstr-eu.20210112.gappssmtp.com header.i=@monstr-eu.20210112.gappssmtp.com header.b="SMiFp01k"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D3309839C3; Wed, 15 Jun 2022 15:21:29 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-ed1-x536.google.com (mail-ed1-x536.google.com [IPv6:2a00:1450:4864:20::536]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id D867284464 for ; Wed, 15 Jun 2022 15:21:26 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=monstr.eu Authentication-Results: phobos.denx.de; spf=none smtp.mailfrom=monstr@monstr.eu Received: by mail-ed1-x536.google.com with SMTP id 25so16083260edw.8 for ; Wed, 15 Jun 2022 06:21:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monstr-eu.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=pOtLZs41fHcgECsjEeIPn5fTsem4JqTfqS3y+qxAMRE=; b=SMiFp01k73bR5CTAJy/2euWF3WO6z35oxRvlUUJDAZfD5yRFZaLLyjuppM90KQ7xgC AcrbWaq29JzyWSY6OIoNtnJIQG7gOpRExb39NYYCYXCATz6QP0fkfTu7M15Tobspuz5Q F1j9VI3MspdM339YWpghnlUVyk3THXYRhszBv1igtTUXo49xiT0COEBcB3x49dJoohMk blbP4qc2TvU1eiyxaDBfB/oSNJSsf4sCLI1S9JuVYP0mcFIyFdgANQ6/iNWZ36el/p46 LboQBZLRC5INuXJb31CgYUth0n+ykcTQiNbbBUxjZEP3nXWKzi3y7rtQrGVDcmL2FjMM lhSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=pOtLZs41fHcgECsjEeIPn5fTsem4JqTfqS3y+qxAMRE=; b=68Au0h+4nsMdg1zlU9x3okflDC89F5CSUDD6zLzHKWczrdx9KcwrZWJm+YnemR7yt/ Baywdwn+zyz8GvcnyLbzCzho6cyo1IHGP35BaSxKw9cYXy+wqQkpzxPoLe406Wam8fFN 2JtAnAB+0ugH+v81JBSwJukVn5UTMYemmqoBFqsKmolzP70BRqE1Wk2yOcgsZf3/l6mU o3ax1HpQ3FUHjZgN+C4UH08yZ3CAgbo98ZF3xPcxJYmuwwsQHpdfkd8yFp42OlwHE4rs tB0RyLIhhJeTSmF2PBFpXeVgSTpd2YKXjCdkAgoiVWueBSpJFy43Wne2attLc+cfTGYi 1aEA== X-Gm-Message-State: AJIora9xVjSIjG3Yz6KHcQ3Rrn/B9u7/CPlo9br7t60V5fa6l5ERmOFB moO76CuHsMJxuliUZ+KoKNJAxtPdfk6ZTA== X-Google-Smtp-Source: AGRyM1tUc03fZJAAgf12QnI+BLU0V0dbshVSqAghj1VWoK4I40xZvgkM12tBqN1Rr9C9DNCL7OCpRQ== X-Received: by 2002:a50:ed12:0:b0:42d:d1d3:493c with SMTP id j18-20020a50ed12000000b0042dd1d3493cmr12496477eds.174.1655299286248; Wed, 15 Jun 2022 06:21:26 -0700 (PDT) Received: from localhost ([2a02:768:2307:40d6::f9e]) by smtp.gmail.com with ESMTPSA id q24-20020aa7d458000000b0042aad9edc9bsm9282881edr.71.2022.06.15.06.21.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Jun 2022 06:21:25 -0700 (PDT) From: Michal Simek X-Google-Original-From: Michal Simek To: u-boot@lists.denx.de, git@xilinx.com Cc: Alistair Delva Subject: [PATCH v4 01/23] tools: relocate-rela: Open binary u-boot file later Date: Wed, 15 Jun 2022 15:20:57 +0200 Message-Id: <9c2b4ebadbe83497db28af02f6af2623793ffdb6.1655299267.git.michal.simek@amd.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: References: MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.5 at phobos.denx.de X-Virus-Status: Clean There is no value to open u-boot binary file so early. Better to check all values first and then open binary file. Signed-off-by: Michal Simek --- (no changes since v1) tools/relocate-rela.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tools/relocate-rela.c b/tools/relocate-rela.c index f0bc548617a4..883987111869 100644 --- a/tools/relocate-rela.c +++ b/tools/relocate-rela.c @@ -73,13 +73,6 @@ int main(int argc, char **argv) return 1; } - f = fopen(argv[1], "r+b"); - if (!f) { - fprintf(stderr, "%s: Cannot open %s: %s\n", - argv[0], argv[1], strerror(errno)); - return 2; - } - if (!read_num(argv[2], &text_base) || !read_num(argv[3], &rela_start) || !read_num(argv[4], &rela_end)) { @@ -95,6 +88,13 @@ int main(int argc, char **argv) rela_start -= text_base; rela_end -= text_base; + f = fopen(argv[1], "r+b"); + if (!f) { + fprintf(stderr, "%s: Cannot open %s: %s\n", + argv[0], argv[1], strerror(errno)); + return 2; + } + fseek(f, 0, SEEK_END); file_size = ftell(f); rewind(f);