From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 59877C433EF for ; Thu, 20 Jan 2022 15:30:49 +0000 (UTC) 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) 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-Google-Smtp-Source: ABdhPJxV9z6HxCJMMNKsuzNAtHx9eN+8UIX1L+cI3i8vY8Tm7HsE/SO0tMRvHV9tiNRtCF1kOO24GA== 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit 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)