From patchwork Thu Jan 20 15:30:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masami Hiramatsu X-Patchwork-Id: 533546 Delivered-To: patch@linaro.org Received: by 2002:ad5:5d50:0:0:0:0:0 with SMTP id x16csp1676746imu; Thu, 20 Jan 2022 07:30:49 -0800 (PST) X-Google-Smtp-Source: ABdhPJxJLCNHp0W7knzfcOort0PJ0eoAQDnhSBe+fyrEEyl/8qfFQ/CCVuG371hdMBncz2IDeRjk X-Received: by 2002:a05:6402:2204:: with SMTP id cq4mr9178919edb.383.1642692648759; Thu, 20 Jan 2022 07:30:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642692648; cv=none; d=google.com; s=arc-20160816; b=xJZCbyWLbWi9r2CBQs3NvqHWY3bioeirx207/v1BD8DEnqLAnTAHOdE0EKAkF7BR9w O+a7mvxqNlQ2c97C3oRPmyknaugZWtXetURo0x347IZ7VbuLLldsDjn/7SvnbSDalpii Bfoj6uiF4mFwuI3eQPHnvU6PcPqIxSTUt8zNk2ubRX+tYJATMEMzy3rDfAN0Db1xwagd WkjWlxwI+U/Ex49LEzSPtfvZ6P1NUJGm9i5NyxKuztLBjnuMp0uPQxF8pc9EHm5mh+UA WzY3+dzH2Aw3d7oCyTas7qoagwUyxiTYo7nGKUNPqNVBStLm+9C3zFRX8Xo1y0OINcZe 0ttA== 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:user-agent:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=bxKyXxb7CGHdTxPJ+1fGaewoFoKvBOjzbp6rBqZ6smA=; b=K15CVMPN/PTBMdWAAcgSLkGFR8iCQja0Ag/ERr7+yJ/J+3SwVMH67UjOIRflW6ASFK ynH7maJ5isPodTViZI4YgzScwdMyEOPO3msUbl70rhkqZnJwcQClviKd7Gjmc3rsei9j 9m9L7jIJb60cnvRjgt9gOoil0jgJI36TWEvEp6iMMLIWAapN0yLQdGeyVXsvejoJ8Q7B 2nodIpA6jP6V0Z8pd3uQJu1q4HUn3DNP4jwp3NFJrzEO0GjW4yuwrQtkbHaOAdSc+i58 a+Byl9lUHD22fEe3YbrZIcGryOf8WJd1k/REX6MYQGzv9YdqKrjLZpaF6fe1vrw+KT9f eJDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=oe5+37AC; 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=pass (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 o10si2283001ejy.529.2022.01.20.07.30.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jan 2022 07:30:48 -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; dkim=pass header.i=@linaro.org header.s=google header.b=oe5+37AC; 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=pass (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 1ECC0838CB; Thu, 20 Jan 2022 16:30:41 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org 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=linaro.org header.i=@linaro.org header.b="oe5+37AC"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 9C52D838CB; Thu, 20 Jan 2022 16:30:39 +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=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) (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 C394C838C7 for ; Thu, 20 Jan 2022 16:30:36 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=masami.hiramatsu@linaro.org Received: by mail-pl1-x629.google.com with SMTP id d1so5449909plh.10 for ; Thu, 20 Jan 2022 07:30:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :user-agent:mime-version:content-transfer-encoding; bh=bxKyXxb7CGHdTxPJ+1fGaewoFoKvBOjzbp6rBqZ6smA=; b=oe5+37ACjEK8oOD/hD3g54TNiacTxmlzy+M094MFs7Gn51ZTZvvs4OrKAgKSLKR2wL /bOIeB5TSFuqfQCv4UhGMZJ8FpeF8reTAu2Yf7AtchLw6TUCYSUiUqeJU6XtELhnrhvN QkM6lmHGyM/zMcR8u22Q2optOVna3HEipLj0/xQ92f1D6vRZ/cZH+3XWmKf/GyVveciK kGR7q4WAZvwf6/q4EBhctZ2DIeZrKpfeHufjbus35aAIoW+JS6M53NNQJbMThQf13F3/ inhGkSZdyXOHB2FRudCUzVQP+t2tQZmQ3O4jSVwhl1tVv08hsEBbwqG6uAldkpZCJ6Fq R6fw== 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:user-agent:mime-version:content-transfer-encoding; bh=bxKyXxb7CGHdTxPJ+1fGaewoFoKvBOjzbp6rBqZ6smA=; b=s/VZizic3QneJVZ5tI6AyaNFi7Z+cKGD7O4l+E+US5w+Z3rq12pPEFO28qMzlrGz7d Z9Dprf4YSuTmXH3MFhhz4USK0mPgT58TAAjVGwVRXzmpzTf+G490cSBKStnR1Z8ePR92 OxRbu0cbVXV6ocAEpVrHUOSJ9U+fsaAgD+9JXJPAXN7fHwZnXLelY4Jjd+dszNI9el/S utXYdgwOp1cC+h0pWo93K5ViHxt/oa1FJLcg+2gl0cf6qsDZMDYW28ESVP/L5/RDdXGT VQIBCrZf59ovr9YS2dojY6BgChwoVqsR9gFt4mzwCHD2d+VEuQfKP6DEr36I4nl5C8bC cF8Q== X-Gm-Message-State: AOAM531yKaVc06DakQUezZB4KBDZooipb95RMPpIOZvjF3oRRKegUDLX wrmdP+ueX8i5mq1Y8DCVb37//lcvgiMZBA== X-Received: by 2002:a17:90a:6d61:: with SMTP id z88mr11156578pjj.165.1642692634996; Thu, 20 Jan 2022 07:30:34 -0800 (PST) Received: from localhost.localdomain (113x37x226x201.ap113.ftth.ucom.ne.jp. [113.37.226.201]) by smtp.gmail.com with ESMTPSA id u21sm3852321pfi.149.2022.01.20.07.30.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jan 2022 07:30:34 -0800 (PST) From: Masami Hiramatsu To: u-boot@lists.denx.de Cc: Masami Hiramatsu , Patrick Delaunay , Patrice Chotard , Heinrich Schuchardt , Alexander Graf , AKASHI Takahiro , Simon Glass , Bin Meng , Ilias Apalodimas , Jose Marinho , Grant Likely , Tom Rini , Etienne Carriere , Sughosh Ganu , Paul Liu Subject: [RFC PATCH 07/14] FWU: Free metadata copy if gpt_get_mdata() failed Date: Fri, 21 Jan 2022 00:30:30 +0900 Message-Id: <164269263036.39378.10026871398998590929.stgit@localhost> X-Mailer: git-send-email 2.25.1 In-Reply-To: <164269255955.39378.260729958623102750.stgit@localhost> References: <164269255955.39378.260729958623102750.stgit@localhost> User-Agent: StGit/0.19 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.2 at phobos.denx.de X-Virus-Status: Clean It is better if a function which returns an error then release all allocated memory resources. This simplifies the mind model and less chance to forgot to free memory and double free. Signed-off-by: Masami Hiramatsu --- lib/fwu_updates/fwu_mdata_gpt_blk.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/fwu_updates/fwu_mdata_gpt_blk.c b/lib/fwu_updates/fwu_mdata_gpt_blk.c index 0259da37c3..7f8b8b68fc 100644 --- a/lib/fwu_updates/fwu_mdata_gpt_blk.c +++ b/lib/fwu_updates/fwu_mdata_gpt_blk.c @@ -215,7 +215,8 @@ static int gpt_get_mdata(struct fwu_mdata **mdata) ret = gpt_read_mdata(desc, *mdata, primary_mpart); if (ret < 0) { log_err("Failed to read the FWU metadata from the device\n"); - return -EIO; + ret = -EIO; + goto out; } ret = fwu_verify_mdata(*mdata, 1); @@ -230,7 +231,8 @@ static int gpt_get_mdata(struct fwu_mdata **mdata) ret = gpt_read_mdata(desc, *mdata, secondary_mpart); if (ret < 0) { log_err("Failed to read the FWU metadata from the device\n"); - return -EIO; + ret = -EIO; + goto out; } ret = fwu_verify_mdata(*mdata, 0); @@ -238,7 +240,10 @@ static int gpt_get_mdata(struct fwu_mdata **mdata) return 0; /* Both the FWU metadata copies are corrupted. */ - return -1; + ret = -1; +out: + free(*mdata); + return ret; } static int gpt_check_mdata_validity(void)