From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM02-SN1-obe.outbound.protection.outlook.com (NAM02-SN1-obe.outbound.protection.outlook.com [40.107.96.82]) by mx.groups.io with SMTP id smtpd.web10.2417.1631575141420605937 for ; Mon, 13 Sep 2021 16:19:01 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@nvidia.com header.s=selector2 header.b=TEcg+Iiy; spf=permerror, err=parse error for token &{10 18 %{i}._ip.%{h}._ehlo.%{d}._spf.vali.email}: invalid domain name (domain: nvidia.com, ip: 40.107.96.82, mailfrom: jbrasen@nvidia.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PYNINU98XgJdkvwzds/pctPmyuD8OGifh78vVltQgurFgl4d5Xk/pv63xW5vav69IkOTG/64qQ0hdnRfbzir69NGyyQ638XS7UpptC428sCOcjk14o+ZzVnpdldlMDEw4DEBFMC6uL7/LNSHNy1nQaK+ixzJZgVqkt7cq5DKuz5SARP3uXYFNvRM85XdAJzNJqYpatMJmdJeCbpYUNlkCy+WdVYGvrjYkVL/IFl/0958eX+J+GQvQSMCxMwwSe65iN/2YBy+ZWWoq/40ZxhwcbYpy7fKQWXSrYDeBJgOSBaWjalFjxnb/gplyMOt+Sp3jP3Ed9PDfpmnYX6kurxd2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=dM1CXGAJ/Lr8TwWyroIerP2UsrvzPfMp3vbUgCWF2+g=; b=XOkH93vle3ji4XDAVSFrsLKInw844FFCoWFf4Xsrir3G7M98FtLB4+x1vyhlntsC0ZJdSnxuvksggKZAfiluD7fPEjPmVZbD7v4/Pnm9fQj12VmiFiXZcL8zXBl9pZ5b6C9cjzMZ19Z4zpn4Z2g/EJP013H+Yitwcp9mWMhBM6aqPRbl2ELZVeriiWnKNRwGhBjQbFZD19VZkTqtxjCk7po8Lwahlrkv/7fkdT+KxKPOhnJjQ23hKIqmSbWkO3PCyEoo8s9dg3Sw6sv1Z2S5CjdEKCqTSuB4n/A7ndrgmAK0xTOVYyqG1AQ6Fzk0st3fogbVkwKRgITEsxTpRwZhzw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.36) smtp.rcpttodomain=kernel.org smtp.mailfrom=nvidia.com; dmarc=pass (p=quarantine sp=none pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=dM1CXGAJ/Lr8TwWyroIerP2UsrvzPfMp3vbUgCWF2+g=; b=TEcg+Iiym3CMqjpHMaV9ph/bv37570Zlac0LLwc+8HBP9snLNdUkRKurJ33OT4itkW7Yk7PiQiwOKzwmVGFZ8fkgItxcoAPm8JrE7CVM3ERIXT7E419v3V+z3UzXc4lyME8wh9sHbTL1yc9m4+IG/qzISj+N/25KDvg0j/5TvrIec9TxBAxeCaslwbzxQ/b8yjhkdPZSCi2dFr3BcsoOLBT8ALo+i6WZsSD5rW4v3SOH6Izyi5PO40QxSDxB/ePP1RJtFmmt+LGrkHnGt+9fTA8tpOHFkb0iVGeNIQOTUCCPN8NDQIOi5prOsKC6m35QYJ2QQFsKZR5wgHul3HBcIw== Received: from MWHPR15CA0043.namprd15.prod.outlook.com (2603:10b6:300:ad::29) by CH2PR12MB3878.namprd12.prod.outlook.com (2603:10b6:610:2a::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.17; Mon, 13 Sep 2021 23:19:00 +0000 Received: from CO1NAM11FT022.eop-nam11.prod.protection.outlook.com (2603:10b6:300:ad:cafe::4) by MWHPR15CA0043.outlook.office365.com (2603:10b6:300:ad::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.14 via Frontend Transport; Mon, 13 Sep 2021 23:18:59 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.36) smtp.mailfrom=nvidia.com; kernel.org; dkim=none (message not signed) header.d=none;kernel.org; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.36 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.36; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.36) by CO1NAM11FT022.mail.protection.outlook.com (10.13.175.199) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4500.14 via Frontend Transport; Mon, 13 Sep 2021 23:18:59 +0000 Received: from HQMAIL111.nvidia.com (172.20.187.18) by HQMAIL101.nvidia.com (172.20.187.10) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Mon, 13 Sep 2021 23:18:59 +0000 Received: from build-jbrasen-20210913T102602203.nvidia.com (172.20.187.5) by mail.nvidia.com (172.20.187.18) with Microsoft SMTP Server id 15.0.1497.18 via Frontend Transport; Mon, 13 Sep 2021 23:18:59 +0000 From: "Jeff Brasen" To: CC: , , , , Jeff Brasen Subject: [PATCH v3 2/4] EmbeddedPkg: AndroidBootImgBoot error handling updates Date: Mon, 13 Sep 2021 23:18:49 +0000 Message-ID: <212f203320b448f4832b31ea4513119693114012.1631574815.git.jbrasen@nvidia.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 In-Reply-To: References: X-NVConfidentiality: public Return-Path: jbrasen@nvidia.com X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 27fd90fd-dcab-478f-feec-08d9770cde0a X-MS-TrafficTypeDiagnostic: CH2PR12MB3878: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:166; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: LHyQKuPEcjyuy7bUueZHLUJggFpypHAe50I6ZjIRTcE6HpUCJBdJrcX0/EedlUMDMPQJ0CaMvjqfNX5fve5lKeGLBLLwiC3hVIBkbYds+mYeWPDjmNBCmGlLUxW+Kd3BmB9vtxSK9xJ0KCXoNAPKDppE6s2jWNESdRsIXJqrUpiSI1skPMvzGFF4xtlrFdEmE8vIRLjwMDNsBpG/f+oYj7/y1A/0S0awxUn1v1b121qz/U88bK0X47CG/fPq/ogGDgPcahnFux7epN1EKI4BcvnG+/BSqCV9j4gXLtiivpyS1JtJKa7Y+QBD6nMreNlcOSLmmj+CFMWF0D054t2HAACc/TmuXaiGqFAKUea9Kfzm2KRhv4AEUIHlChCd8cq4tZ3fhHGOqjLRH0tKthCKmf1eHbPAKhfD7118LCDkj5UKy4cb9HJLlW21sApZ8x5PhfGmgKgQfdGKO29ykkyUK5AkJLcuuGUpQ9VY1NCmovDt1aNbov7LN9B1LH7cSFmOw6OCb+U6HEnEzHs7GXSCzWiL7+Dq9GmxN32rSics+0CmLZpUwm+cTFJjB3ppVLpaGhoBLaD2arUFyIu2sbL8Hai6jASLsgBD/OCYPhZMiMkriNCZEcHqt0IHk7WujfF1K1QhKB/B8/sPsxcYuH2ic+cMhvj3btQLyMZdGA+l6WZTqZjOjwmCZpWTdyOCZ7lRFuUK6nAWOZu9rBff60Sqbw== X-Forefront-Antispam-Report: CIP:216.228.112.36;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:schybrid05.nvidia.com;CAT:NONE;SFS:(4636009)(346002)(376002)(396003)(39860400002)(136003)(46966006)(36840700001)(2906002)(82310400003)(4326008)(8676002)(7696005)(6666004)(7636003)(426003)(478600001)(336012)(15650500001)(36860700001)(54906003)(36906005)(316002)(47076005)(70206006)(83380400001)(2616005)(8936002)(82740400003)(86362001)(186003)(36756003)(26005)(356005)(5660300002)(6916009)(70586007)(107886003);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Sep 2021 23:18:59.7123 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 27fd90fd-dcab-478f-feec-08d9770cde0a X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.112.36];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT022.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB3878 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain Update AndroidBootImgBoot to use a single return point Make sure Kernel args are freed and Image is unloaded. Signed-off-by: Jeff Brasen --- .../AndroidBootImgLib/AndroidBootImgLib.c | 50 +++++++++++-------- 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/EmbeddedPkg/Library/AndroidBootImgLib/AndroidBootImgLib.c b/Em= beddedPkg/Library/AndroidBootImgLib/AndroidBootImgLib.c index 33425060b15d..324933013d91 100644 --- a/EmbeddedPkg/Library/AndroidBootImgLib/AndroidBootImgLib.c +++ b/EmbeddedPkg/Library/AndroidBootImgLib/AndroidBootImgLib.c @@ -382,10 +382,13 @@ AndroidBootImgBoot ( UINTN RamdiskSize; IN VOID *FdtBase; =20 + NewKernelArg =3D NULL; + ImageHandle =3D NULL; + Status =3D gBS->LocateProtocol (&gAndroidBootImgProtocolGuid, NULL, (VOID **) &mAndroidBootImg); if (EFI_ERROR (Status)) { - return Status; + goto Exit; } =20 Status =3D AndroidBootImgGetKernelInfo ( @@ -394,19 +397,19 @@ AndroidBootImgBoot ( &KernelSize ); if (EFI_ERROR (Status)) { - return Status; + goto Exit; } =20 NewKernelArg =3D AllocateZeroPool (ANDROID_BOOTIMG_KERNEL_ARGS_SIZE); if (NewKernelArg =3D=3D NULL) { DEBUG ((DEBUG_ERROR, "Fail to allocate memory\n")); - return EFI_OUT_OF_RESOURCES; + Status =3D EFI_OUT_OF_RESOURCES; + goto Exit; } =20 Status =3D AndroidBootImgUpdateArgs (Buffer, NewKernelArg); if (EFI_ERROR (Status)) { - FreePool (NewKernelArg); - return Status; + goto Exit; } =20 Status =3D AndroidBootImgGetRamdiskInfo ( @@ -415,19 +418,17 @@ AndroidBootImgBoot ( &RamdiskSize ); if (EFI_ERROR (Status)) { - return Status; + goto Exit; } =20 Status =3D AndroidBootImgLocateFdt (Buffer, &FdtBase); if (EFI_ERROR (Status)) { - FreePool (NewKernelArg); - return Status; + goto Exit; } =20 Status =3D AndroidBootImgUpdateFdt (Buffer, FdtBase, RamdiskData, Ramdis= kSize); if (EFI_ERROR (Status)) { - FreePool (NewKernelArg); - return Status; + goto Exit; } =20 KernelDevicePath =3D mMemoryDevicePathTemplate; @@ -440,21 +441,15 @@ AndroidBootImgBoot ( (EFI_DEVICE_PATH *)&KernelDevicePath, (VOID*)(UINTN)Kernel, KernelSize, &ImageHandle)= ; if (EFI_ERROR (Status)) { - // - // With EFI_SECURITY_VIOLATION retval, the Image was loaded and an Ima= geHandle was created - // with a valid EFI_LOADED_IMAGE_PROTOCOL, but the image can not be st= arted right now. - // If the caller doesn't have the option to defer the execution of an = image, we should - // unload image for the EFI_SECURITY_VIOLATION to avoid resource leak. - // - if (Status =3D=3D EFI_SECURITY_VIOLATION) { - gBS->UnloadImage (ImageHandle); - } - return Status; + goto Exit; } =20 // Set kernel arguments Status =3D gBS->HandleProtocol (ImageHandle, &gEfiLoadedImageProtocolGui= d, (VOID **) &ImageInfo); + if (EFI_ERROR (Status)) { + goto Exit; + } ImageInfo->LoadOptions =3D NewKernelArg; ImageInfo->LoadOptionsSize =3D StrLen (NewKernelArg) * sizeof (CHAR16); =20 @@ -464,5 +459,18 @@ AndroidBootImgBoot ( Status =3D gBS->StartImage (ImageHandle, NULL, NULL); // Clear the Watchdog Timer if the image returns gBS->SetWatchdogTimer (0, 0x10000, 0, NULL); - return EFI_SUCCESS; + +Exit: + //Unload image as it will not be used anymore + if (ImageHandle !=3D NULL) { + gBS->UnloadImage (ImageHandle); + ImageHandle =3D NULL; + } + if (EFI_ERROR (Status)) { + if (NewKernelArg !=3D NULL) { + FreePool (NewKernelArg); + NewKernelArg =3D NULL; + } + } + return Status; } --=20 2.17.1