From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1nkQQj-0005LT-2j for mharc-grub-devel@gnu.org; Fri, 29 Apr 2022 09:13:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42394) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nkQQg-0005K1-M4 for grub-devel@gnu.org; Fri, 29 Apr 2022 09:13:02 -0400 Received: from dibed.net-space.pl ([84.10.22.86]:38086) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_3DES_EDE_CBC_SHA1:192) (Exim 4.90_1) (envelope-from ) id 1nkQQe-0001iS-Q8 for grub-devel@gnu.org; Fri, 29 Apr 2022 09:13:02 -0400 Received: from router-fw.i.net-space.pl ([192.168.52.1]:46070 "EHLO tomti.i.net-space.pl") by router-fw-old.i.net-space.pl with ESMTP id S2136933AbiD2NMz (ORCPT ); Fri, 29 Apr 2022 15:12:55 +0200 X-Comment: RFC 2476 MSA function at dibed.net-space.pl logged sender identity as: dkiper Date: Fri, 29 Apr 2022 15:12:52 +0200 From: Daniel Kiper To: Glenn Washburn Cc: grub-devel@gnu.org, Denis 'GNUtoo' Carikli , Patrick Steinhardt , John Lane Subject: Re: [PATCH v9 6/7] luks2: Add detached header support Message-ID: <20220429131252.hcl33m3j6g2ev7mb@tomti.i.net-space.pl> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20170113 (1.7.2) Received-SPF: pass client-ip=84.10.22.86; envelope-from=dkiper@net-space.pl; helo=dibed.net-space.pl X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 29 Apr 2022 13:13:03 -0000 On Mon, Apr 11, 2022 at 06:40:27AM +0000, Glenn Washburn wrote: > If a header file is given to the LUKS2 backend, use that file as the LUKS2 > header, instead of looking for it on the disk. > > Signed-off-by: Glenn Washburn > --- > grub-core/disk/luks2.c | 67 ++++++++++++++++++++++++++++++------------ > 1 file changed, 49 insertions(+), 18 deletions(-) > > diff --git a/grub-core/disk/luks2.c b/grub-core/disk/luks2.c > index 349462c61a..af5bc4fc82 100644 > --- a/grub-core/disk/luks2.c > +++ b/grub-core/disk/luks2.c > @@ -313,13 +313,22 @@ luks2_get_keyslot (grub_luks2_keyslot_t *k, grub_luks2_digest_t *d, grub_luks2_s > > /* Determine whether to use primary or secondary header */ > static grub_err_t > -luks2_read_header (grub_disk_t disk, grub_luks2_header_t *outhdr) > +luks2_read_header (grub_disk_t disk, grub_file_t hdr_file, grub_luks2_header_t *outhdr) > { > grub_luks2_header_t primary, secondary, *header = &primary; > - grub_err_t ret; > + grub_err_t ret = GRUB_ERR_NONE; > > /* Read the primary LUKS header. */ > - ret = grub_disk_read (disk, 0, 0, sizeof (primary), &primary); > + if (hdr_file) if (hdr_file != NULL) and below please... > + { > + if (grub_file_seek (hdr_file, 0) == (grub_off_t) -1) > + ret = grub_errno; Hmmm... Why do not "return grub_errno;"? > + > + else if (grub_file_read (hdr_file, &primary, sizeof (primary)) != sizeof (primary)) > + ret = grub_errno; Ditto. And then you can drop "else"... > + } > + else > + ret = grub_disk_read (disk, 0, 0, sizeof (primary), &primary); > if (ret) ... and this "if" ... Or to be precise add {} after else and convert to "if (ret != GRUB_ERR_NONE)". And it seems to me you can do similar optimizations below. Daniel