From nobody Fri May 3 05:32:43 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+61924+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+61924+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1593633689; cv=none; d=zohomail.com; s=zohoarc; b=j4rrz5oa1lSrAyhQ0iD5UdYB9BoEY5z4cX76OysL4MYAhAxZUowxkN3vUg6s0i44vVw/kBIUUcG7W2ulfW9pWwXfl5FGKZZ72FpfO7qVqfIBZZwQKMbzqN3uKR6Aj65ayQyIHYEZ+5Dhdf7j3GHZd1zc2freJ/ekQX2E8Vynhx4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593633689; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=3IZyaBq1ueCY1r/Tey2yVq+xlHiHavFboN2F60gmTvA=; b=kDNB0ZW40YiCwbCR1fajwl02OqYomLFsf1KZkiLzWWEWHr7a4Q+nntjkPcOZRsyBI0OngUjurPCquYy7ivzOhnjtWyycTtPmwp7vjdFRY5yTw/OKKixJSNO9AnSK5GwYC61TKFFIwEAV5pRKpB7dQDFa4IXVVABsICoouRl67BY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+61924+1787277+3901457@groups.io Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1593633689781763.7657454812887; Wed, 1 Jul 2020 13:01:29 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id gexcYY1788612xOYHPSprhQz; Wed, 01 Jul 2020 13:01:28 -0700 X-Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) by mx.groups.io with SMTP id smtpd.web11.6021.1593633683491217615 for ; Wed, 01 Jul 2020 13:01:23 -0700 X-Received: by mail-wm1-f42.google.com with SMTP id o2so24797721wmh.2 for ; Wed, 01 Jul 2020 13:01:23 -0700 (PDT) X-Gm-Message-State: d3mevQjmdxGFVjQ4XS6xEh2ix1787277AA= X-Google-Smtp-Source: ABdhPJxeJZ00z0IeU61W32XsR2qd0sNnEjIr5cDXrEkUH1NOUQUocIF4IepA9IxDCZSbJZL+0TBCbw== X-Received: by 2002:a1c:1dc7:: with SMTP id d190mr27411712wmd.36.1593633681778; Wed, 01 Jul 2020 13:01:21 -0700 (PDT) X-Received: from vanye.hemma.eciton.net (cpc92302-cmbg19-2-0-cust304.5-4.cable.virginm.net. [82.1.209.49]) by smtp.gmail.com with ESMTPSA id s8sm8519067wru.38.2020.07.01.13.01.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Jul 2020 13:01:21 -0700 (PDT) From: "Leif Lindholm" To: devel@edk2.groups.io Cc: Ard Biesheuvel , macarl@microsoft.com Subject: [edk2-devel] [RFC 1/5] EmbeddedPkg/PrePiLib: style cleanup in FwVol.c Date: Wed, 1 Jul 2020 21:01:14 +0100 Message-Id: <20200701200118.3972-2-leif@nuviainc.com> In-Reply-To: <20200701200118.3972-1-leif@nuviainc.com> References: <20200701200118.3972-1-leif@nuviainc.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,leif@nuviainc.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1593633688; bh=1uRIsMU0t0IbAGPCP+OT7RBtqUOW06n3iIQWCEsH/RE=; h=Cc:Date:From:Reply-To:Subject:To; b=YOjLZtWxugPPeBR4KAbR9B1Qhce0MCy+JtmkTfC3VvKbiMn+ksYq70g/XQkQN15pUfL 4pz5nz/eO5W4M0fT3/d4410HvLZE+6/8kAxkTvrF/1S8llEaGaQ1CnUEn6umnGdFV1wsn U86pnIRelgnt59EA+Oh++vB//cB3ZZ3wTf0= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" Move some curly brackets, change a couple of EFI_D_ to DEBUG_, and fix some intentation. Signed-off-by: Leif Lindholm Reviewed-by: Ard Biesheuvel Tested-by: Ard Biesheuvel --- EmbeddedPkg/Library/PrePiLib/FwVol.c | 44 +++++++++++++--------------- 1 file changed, 20 insertions(+), 24 deletions(-) diff --git a/EmbeddedPkg/Library/PrePiLib/FwVol.c b/EmbeddedPkg/Library/Pre= PiLib/FwVol.c index 881506edddaf..90b5b4444002 100644 --- a/EmbeddedPkg/Library/PrePiLib/FwVol.c +++ b/EmbeddedPkg/Library/PrePiLib/FwVol.c @@ -361,7 +361,7 @@ FfsProcessSection ( // // GetInfo failed // - DEBUG ((EFI_D_ERROR, "Decompress GetInfo Failed - %r\n", Status)); + DEBUG ((DEBUG_ERROR, "Decompress GetInfo Failed - %r\n", Status)); return EFI_NOT_FOUND; } // @@ -392,38 +392,37 @@ FfsProcessSection ( if (Section->Type =3D=3D EFI_SECTION_COMPRESSION) { if (IS_SECTION2 (Section)) { CompressedData =3D (CHAR8 *) ((EFI_COMPRESSION_SECTION2 *) Secti= on + 1); - } - else { + } else { CompressedData =3D (CHAR8 *) ((EFI_COMPRESSION_SECTION *) Sectio= n + 1); } =20 Status =3D UefiDecompress ( - CompressedData, - DstBuffer, - ScratchBuffer - ); + CompressedData, + DstBuffer, + ScratchBuffer + ); } else if (Section->Type =3D=3D EFI_SECTION_GUID_DEFINED) { Status =3D ExtractGuidedSectionDecode ( - Section, - &DstBuffer, - ScratchBuffer, - &AuthenticationStatus - ); + Section, + &DstBuffer, + ScratchBuffer, + &AuthenticationStatus + ); } =20 if (EFI_ERROR (Status)) { // // Decompress failed // - DEBUG ((EFI_D_ERROR, "Decompress Failed - %r\n", Status)); + DEBUG ((DEBUG_ERROR, "Decompress Failed - %r\n", Status)); return EFI_NOT_FOUND; } else { return FfsProcessSection ( - SectionType, - DstBuffer, - DstBufferSize, - OutputBuffer - ); + SectionType, + DstBuffer, + DstBufferSize, + OutputBuffer + ); } } =20 @@ -756,17 +755,14 @@ FfsAnyFvFindFirstFile ( Instance =3D 0; *FileHandle =3D NULL; =20 - while (1) - { + while (1) { Status =3D FfsFindNextVolume (Instance++, VolumeHandle); - if (EFI_ERROR (Status)) - { + if (EFI_ERROR (Status)) { break; } =20 Status =3D FfsFindNextFile (FileType, *VolumeHandle, FileHandle); - if (!EFI_ERROR (Status)) - { + if (!EFI_ERROR (Status)) { break; } } --=20 2.20.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#61924): https://edk2.groups.io/g/devel/message/61924 Mute This Topic: https://groups.io/mt/75244268/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Fri May 3 05:32:43 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+61925+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+61925+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1593633693; cv=none; d=zohomail.com; s=zohoarc; b=hpmZJ6f8npklmaskqgavB7X7TPUG8Bq8DKI+W4lcriRkWJJys8ovTOUhhFermAF6z+94MKqCaiGN9DOuqYPT/vReO7/d4fbx3M4uMsZaN+ej66JsZdyCtVa+eGE7rmhxzNSBmyI/vuyU4P7/0RJ/h4f3YHKyCJygiQIqgALJ2ns= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593633693; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=wAJUOWSxJdFsznNgbiEHW2MUFFu1DYhTpTEXti71zw8=; b=arVgpZcTcY/+lwW+/h5KxXRAEtzKVFcL3fwynpdVPHovsQe805xTObqmnt69OZnudPbn0IDqA6Zgh/iwdUCF6gpLbII/YB/pFVD6QBTB6Lol923P9Wi8BFTCvvXYDrH/xmvb5NFZQ4c4RCkPQAOitD5TEaXt3L20DUMYBdPKOaI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+61925+1787277+3901457@groups.io Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1593633693688613.1257481150706; Wed, 1 Jul 2020 13:01:33 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id fzG0YY1788612xvfl6i34El6; Wed, 01 Jul 2020 13:01:31 -0700 X-Received: from mail-wm1-f65.google.com (mail-wm1-f65.google.com [209.85.128.65]) by mx.groups.io with SMTP id smtpd.web11.6022.1593633684328058033 for ; Wed, 01 Jul 2020 13:01:24 -0700 X-Received: by mail-wm1-f65.google.com with SMTP id j18so23868253wmi.3 for ; Wed, 01 Jul 2020 13:01:24 -0700 (PDT) X-Gm-Message-State: oF4WanzJn7wvJbQCi02ud41cx1787277AA= X-Google-Smtp-Source: ABdhPJzBiJfqtUxZ4az4v7GSFLeCSMIwDv6ap3eyrfGYFqjzp5v+h1FM18kffXtJHHUzW5e5XnM1RA== X-Received: by 2002:a1c:1d46:: with SMTP id d67mr30152835wmd.152.1593633682694; Wed, 01 Jul 2020 13:01:22 -0700 (PDT) X-Received: from vanye.hemma.eciton.net (cpc92302-cmbg19-2-0-cust304.5-4.cable.virginm.net. [82.1.209.49]) by smtp.gmail.com with ESMTPSA id s8sm8519067wru.38.2020.07.01.13.01.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Jul 2020 13:01:22 -0700 (PDT) From: "Leif Lindholm" To: devel@edk2.groups.io Cc: Ard Biesheuvel , macarl@microsoft.com Subject: [edk2-devel] [RFC 2/5] EmbeddedPkg/PrePiLib: drop else if after return Date: Wed, 1 Jul 2020 21:01:15 +0100 Message-Id: <20200701200118.3972-3-leif@nuviainc.com> In-Reply-To: <20200701200118.3972-1-leif@nuviainc.com> References: <20200701200118.3972-1-leif@nuviainc.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,leif@nuviainc.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1593633691; bh=hnpGw1uaBXEAVQVMa87Ad/Z36LHjQ/rf6Ex2T496N+Q=; h=Cc:Date:From:Reply-To:Subject:To; b=iMxagSx4DjaSh1C24dQ5DpL9yaEQSxPSGTYf1wlVgVFiE4J9JC/zU7bgQPPZ0PZeECu NxvSPA9Y6L+Xpf/By5oCqfedUyk6hgck4ZUia+5kwneRVwKWedFkz/RNvjQSiFQIXapaP Pg+X/yZOPhCTtPXt2ay8Sk+ufw+y7LdUUB4= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" Simplify FfsProcessSection logic by breaking the continuation of the main loop as a new if statement that executes if the very first test doesn't end up returning. Signed-off-by: Leif Lindholm Reviewed-by: Ard Biesheuvel Tested-by: Ard Biesheuvel --- EmbeddedPkg/Library/PrePiLib/FwVol.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/EmbeddedPkg/Library/PrePiLib/FwVol.c b/EmbeddedPkg/Library/Pre= PiLib/FwVol.c index 90b5b4444002..fc40d8650be1 100644 --- a/EmbeddedPkg/Library/PrePiLib/FwVol.c +++ b/EmbeddedPkg/Library/PrePiLib/FwVol.c @@ -317,8 +317,9 @@ FfsProcessSection ( } =20 return EFI_SUCCESS; - } else if ((Section->Type =3D=3D EFI_SECTION_COMPRESSION) || (Section-= >Type =3D=3D EFI_SECTION_GUID_DEFINED)) { + } =20 + if ((Section->Type =3D=3D EFI_SECTION_COMPRESSION) || (Section->Type = =3D=3D EFI_SECTION_GUID_DEFINED)) { if (Section->Type =3D=3D EFI_SECTION_COMPRESSION) { if (IS_SECTION2 (Section)) { CompressionSection2 =3D (EFI_COMPRESSION_SECTION2 *) Section; --=20 2.20.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#61925): https://edk2.groups.io/g/devel/message/61925 Mute This Topic: https://groups.io/mt/75244269/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Fri May 3 05:32:43 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+61926+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+61926+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1593633867; cv=none; d=zohomail.com; s=zohoarc; b=mqgPqItYgeIXXDI97OekyyOHIgPPR4CA4ebiv7aGLbkcJpJDzjeP4/onz3PRQ+5v8kyR+P0qJ6C3pbuCdWULbVegnnMoYZIt2e+anjAPjNQV9ugNIAO8CTEKr4zFGEGTbBgWfCXRXTO67EveIQvbdIaWeHlsALEXFbnnJ/MAVss= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593633867; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=ystYYBxqGrFoDMw6jyOdPQc2VhMYT4j3qkV0YDZJHoU=; b=jVMzalATlQ+6/I/4kRnxgBUp/riqpZsek1HuQ4uH2WsgYcM6N14K1j0joN4y8sKLV1er02icGR8GAg9YncdIFmS/evn+GwXi6YJkJ/ZLMr5ptHyWMVMPhGDG4Qv7N43NVvfR6AWi8xccqWYcKz3+HRdpFDjoj5ayh6hs63r3ius= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+61926+1787277+3901457@groups.io Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1593633867034549.5495901527582; Wed, 1 Jul 2020 13:04:27 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 71gNYY1788612xTb4EQgCFle; Wed, 01 Jul 2020 13:04:26 -0700 X-Received: from mail-wr1-f68.google.com (mail-wr1-f68.google.com [209.85.221.68]) by mx.groups.io with SMTP id smtpd.web11.6023.1593633685502234814 for ; Wed, 01 Jul 2020 13:01:25 -0700 X-Received: by mail-wr1-f68.google.com with SMTP id s10so25366965wrw.12 for ; Wed, 01 Jul 2020 13:01:25 -0700 (PDT) X-Gm-Message-State: jizVLzOOC2bDKj27YFM2gK4yx1787277AA= X-Google-Smtp-Source: ABdhPJwU8x/0xOcXIs2mi2KjYZ5/6/279HOy2s9azzSHo/carAaKN0sheQi2Zw5R5tTdBgSTifwukA== X-Received: by 2002:a05:6000:1c7:: with SMTP id t7mr28026184wrx.14.1593633683540; Wed, 01 Jul 2020 13:01:23 -0700 (PDT) X-Received: from vanye.hemma.eciton.net (cpc92302-cmbg19-2-0-cust304.5-4.cable.virginm.net. [82.1.209.49]) by smtp.gmail.com with ESMTPSA id s8sm8519067wru.38.2020.07.01.13.01.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Jul 2020 13:01:23 -0700 (PDT) From: "Leif Lindholm" To: devel@edk2.groups.io Cc: Ard Biesheuvel , macarl@microsoft.com Subject: [edk2-devel] [RFC 3/5] EmbeddedPkg/PrePiLib: refactor IS_SECTION2() handling Date: Wed, 1 Jul 2020 21:01:16 +0100 Message-Id: <20200701200118.3972-4-leif@nuviainc.com> In-Reply-To: <20200701200118.3972-1-leif@nuviainc.com> References: <20200701200118.3972-1-leif@nuviainc.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,leif@nuviainc.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1593633866; bh=hz4MapFZecIAdiORlB7+t1fCNsu1n2Y6VfS4yxS3D6k=; h=Cc:Date:From:Reply-To:Subject:To; b=tAydJomY05LCRHL8aHkFWxwzjxBTk39/tTJVR21fp+SAJTS2IyxArTx5Ucc5BIhDlkJ 6WBUHv4lLwF2IGZOAClWYXDLNtMHNoCTco/eJhBb+I+uk+HQIvkO/yuZG66wJgjoRaOJs geodv5TlygwsfWuH7ibtfriQ/i5z4w5Sf2I= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" There are a bunch of IS_SECTION2() conditional statements in FfsProcessSection, really breaking up the readability. Add a set of static helper functions instead. Signed-off-by: Leif Lindholm Reviewed-by: Ard Biesheuvel Tested-by: Ard Biesheuvel --- EmbeddedPkg/Library/PrePiLib/FwVol.c | 101 ++++++++++++++++----------- 1 file changed, 61 insertions(+), 40 deletions(-) diff --git a/EmbeddedPkg/Library/PrePiLib/FwVol.c b/EmbeddedPkg/Library/Pre= PiLib/FwVol.c index fc40d8650be1..a0672c084471 100644 --- a/EmbeddedPkg/Library/PrePiLib/FwVol.c +++ b/EmbeddedPkg/Library/PrePiLib/FwVol.c @@ -266,6 +266,57 @@ FindFileEx ( return EFI_NOT_FOUND; } =20 +STATIC +UINTN +FfsSectionHeaderSize ( + IN EFI_COMMON_SECTION_HEADER *Section + ) +{ + if (IS_SECTION2 (Section)) { + return sizeof (EFI_COMMON_SECTION_HEADER2); + } + + return sizeof (EFI_COMMON_SECTION_HEADER); +} + +STATIC +UINTN +FfsSectionLength ( + IN EFI_COMMON_SECTION_HEADER *Section + ) +{ + if (IS_SECTION2 (Section)) { + return SECTION2_SIZE (Section); + } + + return SECTION_SIZE (Section); +} + +STATIC +UINTN +FfsSectionCompressionType ( + IN EFI_COMMON_SECTION_HEADER *Section + ) +{ + if (IS_SECTION2 (Section)) { + return ((EFI_COMPRESSION_SECTION2 *)Section)->CompressionType; + } + + return ((EFI_COMPRESSION_SECTION *)Section)->CompressionType; +} + +STATIC +UINTN +FfsCompressionSectionHeaderSize ( + IN EFI_COMMON_SECTION_HEADER *Section + ) +{ + if (IS_SECTION2 (Section)) { + return sizeof (EFI_COMPRESSION_SECTION2); + } + + return sizeof (EFI_COMPRESSION_SECTION); +} =20 /** Go through the file to search SectionType section, @@ -289,8 +340,6 @@ FfsProcessSection ( EFI_STATUS Status; UINT32 SectionLength; UINT32 ParsedLength; - EFI_COMPRESSION_SECTION *CompressionSection; - EFI_COMPRESSION_SECTION2 *CompressionSection2; UINT32 DstBufferSize; VOID *ScratchBuffer; UINT32 ScratchBufferSize; @@ -310,39 +359,22 @@ FfsProcessSection ( } =20 if (Section->Type =3D=3D SectionType) { - if (IS_SECTION2 (Section)) { - *OutputBuffer =3D (VOID *)((UINT8 *) Section + sizeof (EFI_COMMON_= SECTION_HEADER2)); - } else { - *OutputBuffer =3D (VOID *)((UINT8 *) Section + sizeof (EFI_COMMON_= SECTION_HEADER)); - } + *OutputBuffer =3D (VOID *)((UINT8 *)Section + FfsSectionHeaderSize (= Section)); =20 return EFI_SUCCESS; } =20 if ((Section->Type =3D=3D EFI_SECTION_COMPRESSION) || (Section->Type = =3D=3D EFI_SECTION_GUID_DEFINED)) { if (Section->Type =3D=3D EFI_SECTION_COMPRESSION) { - if (IS_SECTION2 (Section)) { - CompressionSection2 =3D (EFI_COMPRESSION_SECTION2 *) Section; - SectionLength =3D SECTION2_SIZE (Section); + SectionLength =3D FfsSectionLength (Section); =20 - if (CompressionSection2->CompressionType !=3D EFI_STANDARD_COMPR= ESSION) { - return EFI_UNSUPPORTED; - } - - CompressedData =3D (CHAR8 *) ((EFI_COMPRESSION_SECTION2 *) Secti= on + 1); - CompressedDataLength =3D (UINT32) SectionLength - sizeof (EFI_CO= MPRESSION_SECTION2); - } else { - CompressionSection =3D (EFI_COMPRESSION_SECTION *) Section; - SectionLength =3D SECTION_SIZE (Section); - - if (CompressionSection->CompressionType !=3D EFI_STANDARD_COMPRE= SSION) { - return EFI_UNSUPPORTED; - } - - CompressedData =3D (CHAR8 *) ((EFI_COMPRESSION_SECTION *) Sectio= n + 1); - CompressedDataLength =3D (UINT32) SectionLength - sizeof (EFI_CO= MPRESSION_SECTION); + if (FfsSectionCompressionType (Section) !=3D EFI_STANDARD_COMPRESS= ION) { + return EFI_UNSUPPORTED; } =20 + CompressedData =3D (VOID *)((UINTN)Section + FfsCompressionSection= HeaderSize (Section)); + CompressedDataLength =3D SectionLength - FfsCompressionSectionHead= erSize (Section); + Status =3D UefiDecompressGetInfo ( CompressedData, CompressedDataLength, @@ -383,19 +415,12 @@ FfsProcessSection ( // DstBuffer still is one section. Adjust DstBuffer offset, skip EFI= section header // to make section data at page alignment. // - if (IS_SECTION2 (Section)) - DstBuffer =3D (UINT8 *)DstBuffer + EFI_PAGE_SIZE - sizeof (EFI_COM= MON_SECTION_HEADER2); - else - DstBuffer =3D (UINT8 *)DstBuffer + EFI_PAGE_SIZE - sizeof (EFI_COM= MON_SECTION_HEADER); + DstBuffer =3D (UINT8 *)DstBuffer + EFI_PAGE_SIZE - FfsSectionHeaderS= ize (Section); // // Call decompress function // if (Section->Type =3D=3D EFI_SECTION_COMPRESSION) { - if (IS_SECTION2 (Section)) { - CompressedData =3D (CHAR8 *) ((EFI_COMPRESSION_SECTION2 *) Secti= on + 1); - } else { - CompressedData =3D (CHAR8 *) ((EFI_COMPRESSION_SECTION *) Sectio= n + 1); - } + CompressedData =3D (VOID *)((UINTN)Section + FfsCompressionSection= HeaderSize (Section)); =20 Status =3D UefiDecompress ( CompressedData, @@ -427,11 +452,7 @@ FfsProcessSection ( } } =20 - if (IS_SECTION2 (Section)) { - SectionLength =3D SECTION2_SIZE (Section); - } else { - SectionLength =3D SECTION_SIZE (Section); - } + SectionLength =3D FfsSectionLength (Section); // // SectionLength is adjusted it is 4 byte aligned. // Go to the next section --=20 2.20.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#61926): https://edk2.groups.io/g/devel/message/61926 Mute This Topic: https://groups.io/mt/75244270/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Fri May 3 05:32:43 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+61927+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+61927+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1593633704; cv=none; d=zohomail.com; s=zohoarc; b=fDQNdGm5hvfrZ4XdPe4Qg1EFi8iLD3rjHG0zhuh9fhKmrYupovif+tsakMuSspHQi/t7C+zQBvPBGnjzDzLoLPzx47x2+2DM2EuO+WXxChrz1X3IkmA8/IERhKWNVOrewUax+SMGFARtqhQs00gre7G+SMEEXKjeoZ5m3P7sg2o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593633704; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=oikTXvUoalcT7DELIRMU4CXOCtuRY5PTMqxbmCoK21E=; b=LyzpIfcmaNuNkotMl+s1Fk1oifSQ6xa10f9hT3yxIKwjEWHntr3C8A1KII3+XYLSJSPOX/R9psNPaVSaWJUjV9sJ+1NkaW+SczYbpxnWAQtYHmtT6oaMeu1AcfCEmKH/a8qdzSPifL8x5Blgj4W+ZkHxEpcPPLMTSxQRZ3o4Jnw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+61927+1787277+3901457@groups.io Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1593633704368963.8398630216417; Wed, 1 Jul 2020 13:01:44 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id n5uAYY1788612xwmSXiXClTr; Wed, 01 Jul 2020 13:01:44 -0700 X-Received: from mail-wr1-f67.google.com (mail-wr1-f67.google.com [209.85.221.67]) by mx.groups.io with SMTP id smtpd.web11.6025.1593633686411021040 for ; Wed, 01 Jul 2020 13:01:26 -0700 X-Received: by mail-wr1-f67.google.com with SMTP id q5so25391197wru.6 for ; Wed, 01 Jul 2020 13:01:26 -0700 (PDT) X-Gm-Message-State: td3zto7oIyCYPrT8VAdz93KFx1787277AA= X-Google-Smtp-Source: ABdhPJwMkUp3D57ffZ6IILNygKheSEaznMsI0vdEJ+fVxuhkweo0Vfta82CAyXv2izEemSPggk3ckg== X-Received: by 2002:adf:e4c9:: with SMTP id v9mr27760635wrm.62.1593633684632; Wed, 01 Jul 2020 13:01:24 -0700 (PDT) X-Received: from vanye.hemma.eciton.net (cpc92302-cmbg19-2-0-cust304.5-4.cable.virginm.net. [82.1.209.49]) by smtp.gmail.com with ESMTPSA id s8sm8519067wru.38.2020.07.01.13.01.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Jul 2020 13:01:23 -0700 (PDT) From: "Leif Lindholm" To: devel@edk2.groups.io Cc: Ard Biesheuvel , macarl@microsoft.com Subject: [edk2-devel] [RFC 4/5] EmbeddedPkg/PrePiLib: drop spurious re-init of CompressedData Date: Wed, 1 Jul 2020 21:01:17 +0100 Message-Id: <20200701200118.3972-5-leif@nuviainc.com> In-Reply-To: <20200701200118.3972-1-leif@nuviainc.com> References: <20200701200118.3972-1-leif@nuviainc.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,leif@nuviainc.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1593633704; bh=bvKoPbyffai7IN9RNakkH1u7BiWnsKACGoVhHKiD8Vo=; h=Cc:Date:From:Reply-To:Subject:To; b=RlScgLtb/ErEQz5FcugQQxdwV8MXX6LcIPxLx7m8IluQqts4aK8/4yaKWGPHGKouwc1 r36PL/H1F0oMOGRrCwWZ9h8UMgYw1gSpA39vJNprP+XjiHao4iD8lh9HEtA/Pl3HEHbju G5UbkLs/PXWSpi9QASqVxbgak6G7ldLhe60= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" After the refactoring, it is very clear that CompressedData is initialized twice, using exactly the same values. Drop the second one. Signed-off-by: Leif Lindholm Reviewed-by: Ard Biesheuvel Tested-by: Ard Biesheuvel --- EmbeddedPkg/Library/PrePiLib/FwVol.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/EmbeddedPkg/Library/PrePiLib/FwVol.c b/EmbeddedPkg/Library/Pre= PiLib/FwVol.c index a0672c084471..083bc27efead 100644 --- a/EmbeddedPkg/Library/PrePiLib/FwVol.c +++ b/EmbeddedPkg/Library/PrePiLib/FwVol.c @@ -420,8 +420,6 @@ FfsProcessSection ( // Call decompress function // if (Section->Type =3D=3D EFI_SECTION_COMPRESSION) { - CompressedData =3D (VOID *)((UINTN)Section + FfsCompressionSection= HeaderSize (Section)); - Status =3D UefiDecompress ( CompressedData, DstBuffer, --=20 2.20.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#61927): https://edk2.groups.io/g/devel/message/61927 Mute This Topic: https://groups.io/mt/75244272/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Fri May 3 05:32:43 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+61928+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+61928+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1593633705; cv=none; d=zohomail.com; s=zohoarc; b=H6gF3Cb+DHIE81cmFepMbE8SUKlTRe10ifaMZS2+XYRUnNtVxVc2TiWlbKfINgOpAMHjEKchwjXTF3a39QVmZ6ieepuBYyt7MAhYErRi19Qj5HnHO2lGm6QP4J9msh+2pVSmvMtJD8gHQgTG3n+abIcXSGc0JfFxQaikgPEXpGk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593633705; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=oN5x5roW74A2zcGPKnCuB2sdEA08LHuuquDMwLok7IQ=; b=ACHxs2u4QeTSjCliBTV3Wd0MqyPSD+wVN5gGEr0p/z7Fi1iIODulb6sMGXrptqd18CFe3RkUlk2pGCGDLfoeHaQSTH4PrRDvpPbLYWliQR0dRQFxTv9V5XohLF5u1glJEbijyuPb6175F2yq/qTsRgUjipclSvMRDQw79tdVeeA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+61928+1787277+3901457@groups.io Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1593633705680460.208691004666; Wed, 1 Jul 2020 13:01:45 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 2YwDYY1788612x2wtKpMmRaE; Wed, 01 Jul 2020 13:01:45 -0700 X-Received: from mail-wm1-f68.google.com (mail-wm1-f68.google.com [209.85.128.68]) by mx.groups.io with SMTP id smtpd.web10.5814.1593633687761712969 for ; Wed, 01 Jul 2020 13:01:28 -0700 X-Received: by mail-wm1-f68.google.com with SMTP id w3so12330687wmi.4 for ; Wed, 01 Jul 2020 13:01:27 -0700 (PDT) X-Gm-Message-State: aXeQmKhQcOePnz96BjvHc8zVx1787277AA= X-Google-Smtp-Source: ABdhPJya/g955SzOh/fSFTcWUTN1u4XSwXOAJeJFxjOM8kcxGqpRutkuKCFR313yXi513Nj8c197vg== X-Received: by 2002:a7b:c348:: with SMTP id l8mr30463530wmj.54.1593633685839; Wed, 01 Jul 2020 13:01:25 -0700 (PDT) X-Received: from vanye.hemma.eciton.net (cpc92302-cmbg19-2-0-cust304.5-4.cable.virginm.net. [82.1.209.49]) by smtp.gmail.com with ESMTPSA id s8sm8519067wru.38.2020.07.01.13.01.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Jul 2020 13:01:25 -0700 (PDT) From: "Leif Lindholm" To: devel@edk2.groups.io Cc: Ard Biesheuvel , macarl@microsoft.com Subject: [edk2-devel] [RFC 5/5] EmbeddedPkg/PrePiLib: break section extraction info into helper function Date: Wed, 1 Jul 2020 21:01:18 +0100 Message-Id: <20200701200118.3972-6-leif@nuviainc.com> In-Reply-To: <20200701200118.3972-1-leif@nuviainc.com> References: <20200701200118.3972-1-leif@nuviainc.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,leif@nuviainc.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1593633705; bh=qgZFpUd3jhtysKjFyChnF89CJlzmGZ3kiCnJYyYiUuA=; h=Cc:Date:From:Reply-To:Subject:To; b=enTTmvGmQI01yNYvxZ5aMioRjPJAJ5CyGMs9PywK6tTdsEzxWAPzd2NDSORjYbhJ+fJ CM3HHneWLd8fgmpHkPvUHXuyeXadV6PQRmd2J4rGxMAYoWv1W44gvz8re4VA3h2s+nXS8 35sGelvIM0XXEl1AgkHUXrc27RI1fARmks4= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" Create a new helper function FfsGetExtractionInfo, which handles figuring out the buffer sizes needed for extracting UefiCompressed or GuidedSection sections, and also hides away some of the differences between the two, getting rid of a bunch of local variables. Signed-off-by: Leif Lindholm Reviewed-by: Ard Biesheuvel Tested-by: Ard Biesheuvel --- EmbeddedPkg/Library/PrePiLib/FwVol.c | 90 +++++++++++++++++----------- 1 file changed, 55 insertions(+), 35 deletions(-) diff --git a/EmbeddedPkg/Library/PrePiLib/FwVol.c b/EmbeddedPkg/Library/Pre= PiLib/FwVol.c index 083bc27efead..d0f91efa77a1 100644 --- a/EmbeddedPkg/Library/PrePiLib/FwVol.c +++ b/EmbeddedPkg/Library/PrePiLib/FwVol.c @@ -318,6 +318,50 @@ FfsCompressionSectionHeaderSize ( return sizeof (EFI_COMPRESSION_SECTION); } =20 +STATIC +EFI_STATUS +FfsGetExtractionInfo ( + IN EFI_COMMON_SECTION_HEADER *Section, + OUT UINT32 *SectionLength, + IN OUT VOID **SrcBuffer, + OUT UINT32 *DstBufferSize, + OUT UINT32 *ScratchBufferSize + ) +{ + EFI_STATUS Status; + + if (Section->Type =3D=3D EFI_SECTION_COMPRESSION) { + *SectionLength =3D FfsSectionLength (Section); + + if (FfsSectionCompressionType (Section) !=3D EFI_STANDARD_COMPRESSION)= { + return EFI_UNSUPPORTED; + } + + *SrcBuffer =3D (VOID *)((UINTN)Section + FfsCompressionSectionHeaderSi= ze (Section)); + Status =3D UefiDecompressGetInfo ( + *SrcBuffer, + *SectionLength - FfsCompressionSectionHeaderSize (Section), + DstBufferSize, + ScratchBufferSize + ); + } else if (Section->Type =3D=3D EFI_SECTION_GUID_DEFINED) { + UINT16 Ignored; + + *SrcBuffer =3D Section; + + Status =3D ExtractGuidedSectionGetInfo ( + *SrcBuffer, + DstBufferSize, + ScratchBufferSize, + &Ignored // SectionAttribute not used by this library + ); + } else { + Status =3D EFI_UNSUPPORTED; + } + + return Status; +} + /** Go through the file to search SectionType section, when meeting an encapsuled section. @@ -344,15 +388,11 @@ FfsProcessSection ( VOID *ScratchBuffer; UINT32 ScratchBufferSize; VOID *DstBuffer; - UINT16 SectionAttribute; - UINT32 AuthenticationStatus; - CHAR8 *CompressedData; - UINTN CompressedDataLength; - + VOID *SrcBuffer; =20 *OutputBuffer =3D NULL; ParsedLength =3D 0; - Status =3D EFI_NOT_FOUND; + while (ParsedLength < SectionSize) { if (IS_SECTION2 (Section)) { ASSERT (SECTION2_SIZE (Section) > 0x00FFFFFF); @@ -364,32 +404,11 @@ FfsProcessSection ( return EFI_SUCCESS; } =20 + SectionLength =3D FfsSectionLength (Section); + if ((Section->Type =3D=3D EFI_SECTION_COMPRESSION) || (Section->Type = =3D=3D EFI_SECTION_GUID_DEFINED)) { - if (Section->Type =3D=3D EFI_SECTION_COMPRESSION) { - SectionLength =3D FfsSectionLength (Section); - - if (FfsSectionCompressionType (Section) !=3D EFI_STANDARD_COMPRESS= ION) { - return EFI_UNSUPPORTED; - } - - CompressedData =3D (VOID *)((UINTN)Section + FfsCompressionSection= HeaderSize (Section)); - CompressedDataLength =3D SectionLength - FfsCompressionSectionHead= erSize (Section); - - Status =3D UefiDecompressGetInfo ( - CompressedData, - CompressedDataLength, - &DstBufferSize, - &ScratchBufferSize - ); - } else if (Section->Type =3D=3D EFI_SECTION_GUID_DEFINED) { - Status =3D ExtractGuidedSectionGetInfo ( - Section, - &DstBufferSize, - &ScratchBufferSize, - &SectionAttribute - ); - } - + Status =3D FfsGetExtractionInfo (Section, &SectionLength, &SrcBuffer, + &DstBufferSize, &ScratchBufferSize); if (EFI_ERROR (Status)) { // // GetInfo failed @@ -421,16 +440,18 @@ FfsProcessSection ( // if (Section->Type =3D=3D EFI_SECTION_COMPRESSION) { Status =3D UefiDecompress ( - CompressedData, + SrcBuffer, DstBuffer, ScratchBuffer ); } else if (Section->Type =3D=3D EFI_SECTION_GUID_DEFINED) { + UINT32 Ignored; + Status =3D ExtractGuidedSectionDecode ( - Section, + SrcBuffer, &DstBuffer, ScratchBuffer, - &AuthenticationStatus + &Ignored // AuthenticationStatus not used by this libr= ary ); } =20 @@ -450,7 +471,6 @@ FfsProcessSection ( } } =20 - SectionLength =3D FfsSectionLength (Section); // // SectionLength is adjusted it is 4 byte aligned. // Go to the next section --=20 2.20.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#61928): https://edk2.groups.io/g/devel/message/61928 Mute This Topic: https://groups.io/mt/75244275/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-