From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (NAM12-MW2-obe.outbound.protection.outlook.com [40.107.244.85]) by mx.groups.io with SMTP id smtpd.web12.1613.1630528114503095063 for ; Wed, 01 Sep 2021 13:28:34 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@nvidia.com header.s=selector2 header.b=D9VWnaZW; 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.244.85, mailfrom: jbrasen@nvidia.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EjcIs1Y60bxgJcyIt85YxDP1fzY/LzA29Z0VD3Wu6nM6f8f4atTCBJID3uiXl15Af7Yxiv5PYfJbYYgDmgBH6hwOGdcKjOBJK9HKSJUT07p/54ZQ13AywEM/GN0nL9jbMgE4WIkTDCLCxgZYdeLC274q88FUWnI5gtdpxwjpU3q4GsfFlmHhfBN2I6MuTtFYw6Ua1CZoMXnQwEv6/fsI5M8Ug6cC04HHY1QFfheTnHoyGrNXVHY/gICUoZ1b7ErHbFDbWfKI6FqCMOEvVpTzAZMd3GLY6hkGq4hb/eSziGn2FOB07m4UePRKPr5M50Z9VMEtCBRGDpyUj3IDcCwR5w== 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:X-MS-Exchange-SenderADCheck; bh=iVdvCNhbdWuWJ3GvTqMImUzZ134L8tbr0DBDZjG89R8=; b=AcHxdms5cbwPrVpzqJwHLeIfUM5yqbidfJx4xl34q1FeBK8Fwg1+3yRA5bT1nVG5jcC/Lvkkd3CmYc0/28OmtZVTnq3CCZFe1/HV7pAi2dAnq2TakIQ0ND+1sjW2Q+JdlJ6kRUC39rgLRFT6dbp1naE0WphSNkLXZjJs1SHf35tTOQlMBj3UthTGcf8tM3KxbMQYEH59kz9Ew4l534NHMh8vcyHbrYu18fzkHgsxHtOC+uzK1ycIgGUOEtNjXLPya8XQfHb7Uqthat9Ts89VTvssl36ANu6lS79la6/GxtQmN7+SJTcndWeO2exow5bjGYso+GwqYvwyuB+vdif2gQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.34) smtp.rcpttodomain=nuviainc.com 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=iVdvCNhbdWuWJ3GvTqMImUzZ134L8tbr0DBDZjG89R8=; b=D9VWnaZWtlWLYbLD8s6lC27YxPO3gWHmqQYuIZUBZVAyjayAC7mlOQPQcBiHsXuog6G8UUcYPSqqyaSU6ZQ+cYrO5HU3i1PiGWKiiN4cwrdWmQ3oM+HbNFKFlC53VAq2FjWY2AObbDr0JnGaCne535ujxVMeBb9z8oqlX0pUu19ZV5BxiWGpGrE+sui8XRmKvOvMg/hMisgBBF/WHBd8lX1+CerJARQdjxhyR/C7k3/W+l5sEKDba+5ux9By1Rs9Fj/Rpv5yQWpjUSzblfoCZaw2ReSbSNgvKLSNsq64kLOBzBTnQTCQkka9AGfxseaCNS9Hb4MjE+uzv0Q4Gn9Hiw== Received: from DM6PR05CA0042.namprd05.prod.outlook.com (2603:10b6:5:335::11) by DM6PR12MB3225.namprd12.prod.outlook.com (2603:10b6:5:188::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4457.23; Wed, 1 Sep 2021 20:28:32 +0000 Received: from DM6NAM11FT029.eop-nam11.prod.protection.outlook.com (2603:10b6:5:335:cafe::23) by DM6PR05CA0042.outlook.office365.com (2603:10b6:5:335::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.10 via Frontend Transport; Wed, 1 Sep 2021 20:28:32 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.34) smtp.mailfrom=nvidia.com; nuviainc.com; dkim=none (message not signed) header.d=none;nuviainc.com; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.34 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.34; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.34) by DM6NAM11FT029.mail.protection.outlook.com (10.13.173.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4478.19 via Frontend Transport; Wed, 1 Sep 2021 20:28:32 +0000 Received: from HQMAIL105.nvidia.com (172.20.187.12) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 1 Sep 2021 20:28:31 +0000 Received: from HQMAIL101.nvidia.com (172.20.187.10) by HQMAIL105.nvidia.com (172.20.187.12) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 1 Sep 2021 20:28:31 +0000 Received: from build-jbrasen-20210819T103534360.nvidia.com (172.20.187.6) by mail.nvidia.com (172.20.187.10) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Wed, 1 Sep 2021 20:28:31 +0000 From: "Jeff Brasen" To: CC: , , , , Jeff Brasen Subject: [PATCH v2 1/2] EmbeddedPkg: AndroidBootImgBoot error handling updates Date: Wed, 1 Sep 2021 20:28:26 +0000 Message-ID: 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: 4d125788-95d5-47ea-bf88-08d96d871127 X-MS-TrafficTypeDiagnostic: DM6PR12MB3225: 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: QMTedT3vSwqsDQ+3mOx7QHqvRLx/cvTIhpYbGI4hcQzG/EuDp5Mg1aEo0wjtFQsppGZV4Y/jaP/aX0JpnWJ9yFzj3/ExuzesUylzaumCzV2cOD1OxPsOWECQe9kfuB0wB9EulZlgW7nh05ExFGjZEqyVqCQ5dh7D0+gZMyu0phUTjeeBQp0gRGI7AGjScsl5US32KpRcYAWFBRLoxPpG9NvA6FYO9WgRpxy8O5SDam9nZqXnuMZjgUQit9fLfnvo7TKMKS6N2fLT+F+86QGkS7khGcW/tvFyzzEGnYvi/7lxmreeB/TjwVfUeWGB7zvOhpZ17dZtv5dZ7hG/Kh5GEoZC+PZ4DoI6Ed0ZNPY8/ax7U07Gw/xes2G922PzgbnkZ+F8xMPyMDs95WM8OJbLQZrQdxqZ7OxN9GL0WM6W+rXLajbG6rt1W3FqWWI9VueelMzvvggHmzIqwXQ1jXzJ9eRn3IFxg042EqakWNkROIzGyUOxPATckaOy1uXyo5vc5HuROezK4gtIOe+HChMcmC1W+6/ueOuIwD+f897CdQPfk20QKOO8c6SEDtISClFCTvcpKKICk6sJh6NSeqM8KIlSCnkaH8UadgApjYLRhpDRDyrfA/vH41ElRpYNomQAXXS5IczHrfqg3PdQ+K+o6OXkoBdq/3fK8tiIsgX9UDqFqTH5gngsxDhOjOFGpWvMTtHKJxQJoQGKoRzssy6jRA== X-Forefront-Antispam-Report: CIP:216.228.112.34;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:schybrid03.nvidia.com;CAT:NONE;SFS:(4636009)(36840700001)(46966006)(2906002)(316002)(70586007)(36906005)(54906003)(70206006)(2616005)(107886003)(4326008)(6916009)(356005)(47076005)(83380400001)(86362001)(36756003)(8676002)(82310400003)(26005)(7636003)(36860700001)(336012)(15650500001)(426003)(7696005)(508600001)(5660300002)(186003)(8936002)(6666004);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Sep 2021 20:28:32.3487 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4d125788-95d5-47ea-bf88-08d96d871127 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.34];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT029.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3225 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 bbc240c3632a..3c617649f735 100644 --- a/EmbeddedPkg/Library/AndroidBootImgLib/AndroidBootImgLib.c +++ b/EmbeddedPkg/Library/AndroidBootImgLib/AndroidBootImgLib.c @@ -384,10 +384,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 ( @@ -396,19 +399,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 ( @@ -417,19 +420,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; @@ -442,21 +443,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 @@ -466,5 +461,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