From patchwork Thu Jan 21 11:52:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 367824 Delivered-To: patch@linaro.org Received: by 2002:a02:a60d:0:0:0:0:0 with SMTP id c13csp495040jam; Thu, 21 Jan 2021 03:52:55 -0800 (PST) X-Google-Smtp-Source: ABdhPJyOnEB5yWIOi/8fJI17tMYso6BkkG9oN6nBDA+eJOKFC2H+/pdHmiFtd1JovpPq6TtQxquh X-Received: by 2002:a17:906:b756:: with SMTP id fx22mr8422729ejb.406.1611229975316; Thu, 21 Jan 2021 03:52:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611229975; cv=none; d=google.com; s=arc-20160816; b=f16/dO5nIQovTDTLdUOVK4xNLm9vPUacCRCcDTdF7ZZWJaFBzTL5CMaTegWQtPIPWn ZCMOdXCfk7+jygELGWpmURKdTQwR1Nw7gtPILINKvXloYMmrWQ1KCOA+iNN5wLwtsW+a pWaHmPzDOphvJ/o9QCLJ8g31BEM8Wu7FULjpbAKfPAoZ9FN5NVd3yFRYPABoX1uSLnLC zuh4XCdCKM6IuBZuYXsXKfwGLAGMuNT5atCObkdQxFgOWK7VbokfkIQp9clxshR04Ktg vxnGu67CvChcfso3uiwFA05X2XKtM72vM0YuqGcm0DuUwnS3v/0ohnRTtG5li25BiNKW T9Pg== 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:message-id:date:subject:cc:to :from; bh=vEXhowqlAyhSF0qB03zOiYFwRjgiEoWHO+OybjY50MM=; b=liCs0I3dluyGYEBQWrY7OXjbsSdBlqKcycrOxQnUJW1xXlbXVYUhU6UYleUzHvLJ2U wHZJNCd1fz2GWcnkJE9W0miGk08F08D/tg6oKg8+KNTM/X3VDTF9gDN7B35BJPvrMyl6 U4oNemxxHrttDNCEhzJaEP3YlP9sHHbQfqwZVZWjjsIRiwPbB3DngDtqwMdSGXcfULGd 0pGmwWaJP34ZuTlyO2AJykrpczgXY+8X6hXf6LLfxFkNFXoW+pNGymoq+d6/m60U7V9h P1N0YynY48rixfIi2exf90vyt2ioTftodvfttnWI1aYZOo2X8DTQtaJOERd7ws674rg2 x7iw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id h14si1625016ejt.198.2021.01.21.03.52.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Jan 2021 03:52:55 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 50C7E82A43; Thu, 21 Jan 2021 12:52:52 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id 9092482A49; Thu, 21 Jan 2021 12:52:50 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by phobos.denx.de (Postfix) with ESMTP id 6C5A882735 for ; Thu, 21 Jan 2021 12:52:47 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=fail smtp.mailfrom=sughosh.ganu@linaro.org Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id F223511D4; Thu, 21 Jan 2021 03:52:45 -0800 (PST) Received: from a076522.blr.arm.com (a076522.blr.arm.com [10.162.16.44]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 41DBE3F719; Thu, 21 Jan 2021 03:52:44 -0800 (PST) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Tom Rini , Takahiro Akashi , Sughosh Ganu Subject: [PATCH] mkeficapsule: Free up resources used for adding public key to dtb Date: Thu, 21 Jan 2021 17:22:21 +0530 Message-Id: <20210121115221.16058-1-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.17.1 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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.102.3 at phobos.denx.de X-Virus-Status: Clean Fix the issues flagged by Coverity on resources not being released in the add_public_key function. Signed-off-by: Sughosh Ganu --- tools/mkeficapsule.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) -- 2.17.1 diff --git a/tools/mkeficapsule.c b/tools/mkeficapsule.c index 270943fc90..caf0a1b231 100644 --- a/tools/mkeficapsule.c +++ b/tools/mkeficapsule.c @@ -150,6 +150,7 @@ static int add_public_key(const char *pkey_file, const char *dtb_file, if (srcfd == -1) { fprintf(stderr, "%s: Can't open %s: %s\n", __func__, pkey_file, strerror(errno)); + ret = -1; goto err; } @@ -157,6 +158,7 @@ static int add_public_key(const char *pkey_file, const char *dtb_file, if (ret == -1) { fprintf(stderr, "%s: Can't stat %s: %s\n", __func__, pkey_file, strerror(errno)); + ret = -1; goto err; } @@ -167,6 +169,7 @@ static int add_public_key(const char *pkey_file, const char *dtb_file, if ((sptr == MAP_FAILED) || (errno != 0)) { fprintf(stderr, "%s: Failed to mmap %s:%s\n", __func__, pkey_file, strerror(errno)); + ret = -1; goto err; } @@ -175,6 +178,7 @@ static int add_public_key(const char *pkey_file, const char *dtb_file, if (destfd == -1) { fprintf(stderr, "%s: Can't open %s: %s\n", __func__, dtb_file, strerror(errno)); + ret = -1; goto err; } @@ -189,6 +193,7 @@ static int add_public_key(const char *pkey_file, const char *dtb_file, if (ftruncate(destfd, dtb.st_size)) { fprintf(stderr, "%s: Can't expand %s: %s\n", __func__, dtb_file, strerror(errno)); + ret = -1; goto err;; } @@ -199,11 +204,13 @@ static int add_public_key(const char *pkey_file, const char *dtb_file, if ((dptr == MAP_FAILED) || (errno != 0)) { fprintf(stderr, "%s: Failed to mmap %s:%s\n", __func__, dtb_file, strerror(errno)); + ret = -1; goto err; } if (fdt_check_header(dptr)) { fprintf(stderr, "%s: Invalid FDT header\n", __func__); + ret = -1; goto err; } @@ -211,6 +218,7 @@ static int add_public_key(const char *pkey_file, const char *dtb_file, if (ret) { fprintf(stderr, "%s: Cannot expand FDT: %s\n", __func__, fdt_strerror(ret)); + ret = -1; goto err; } @@ -219,10 +227,11 @@ static int add_public_key(const char *pkey_file, const char *dtb_file, if (ret < 0) { fprintf(stderr, "%s: Unable to add public key to the FDT\n", __func__); + ret = -1; goto err; } - return 0; + ret = 0; err: if (sptr) @@ -237,7 +246,7 @@ err: if (destfd >= 0) close(destfd); - return -1; + return ret; } static int create_fwbin(char *path, char *bin, efi_guid_t *guid,