Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1jcacL-0006GG-5g for mharc-grub-devel@gnu.org; Sat, 23 May 2020 16:19:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59364) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jcacJ-0006DP-Lk for grub-devel@gnu.org; Sat, 23 May 2020 16:19:35 -0400 Received: from mailout03.mx.bawue.net ([193.7.176.64]:48761) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jcacI-0002jJ-MS for grub-devel@gnu.org; Sat, 23 May 2020 16:19:35 -0400 Received: from infty.fritz.box (p5b17584c.dip0.t-ipconnect.de [91.23.88.76]) (Authenticated sender: pdim@bawue.de) by smtp.bawue.net (Postfix) with ESMTPSA id 720CB2013C; Sat, 23 May 2020 22:19:30 +0200 (CEST) From: Hans Ulrich Niedermann To: grub-devel@gnu.org Cc: Hans Ulrich Niedermann Subject: [PATCH RFC] mb2 loader: Use the same iteration code for MB2 as for MB1 Date: Sat, 23 May 2020 22:19:23 +0200 Message-Id: <20200523201923.648465-3-hun@n-dimensional.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200523201923.648465-1-hun@n-dimensional.de> References: <20200523201923.648465-1-hun@n-dimensional.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Virus-Scanner: SAV Dynamic Interface 2.6.0, Engine: 3.77.1, SAV: 5.75 (F8623BC6) on relay01.mx.bawue.net using milter-sssp 0.1.0 X-Virus-Scan: Found to be clean. Received-SPF: pass client-ip=193.7.176.64; envelope-from=hun@n-dimensional.de; helo=mailout03.mx.bawue.net X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/23 16:19:33 X-ACL-Warn: Detected OS = Linux 3.11 and newer [fuzzy] X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 23 May 2020 20:19:35 -0000 This avoids the divisions by 4 to compensate for using an array of 32bit values instead of bytes in MB2 find_header(), just like the MB1 find_header() does it. Also uses the same principle for iterating through the MB2 header tags. Why not use the same code for iterating over memory locations in the Multiboot 2 loader as we do in the Multiboot 1 loader? diff --git a/grub-core/loader/multiboot_mbi2.c b/grub-core/loader/multiboot_mbi2.c index 026109e69..38ddea088 100644 --- a/grub-core/loader/multiboot_mbi2.c +++ b/grub-core/loader/multiboot_mbi2.c @@ -95,7 +95,7 @@ find_header (grub_properly_aligned_t *buffer, grub_ssize_t len) magic plus terminator tag) and aligned on an 8-byte boundary. */ for (header = (struct multiboot_header *) buffer; ((char *) header <= (char *) buffer + len - 24); - header = (struct multiboot_header *) ((grub_uint32_t *) header + MULTIBOOT_HEADER_ALIGN / 4)) + header = (struct multiboot_header *) ((char *) header + MULTIBOOT_HEADER_ALIGN)) { if (header->magic == MULTIBOOT2_HEADER_MAGIC && !(header->magic + header->architecture @@ -152,7 +152,7 @@ grub_multiboot2_load (grub_file_t file, const char *filename) for (tag = (struct multiboot_header_tag *) (header + 1); tag->type != MULTIBOOT_TAG_TYPE_END; - tag = (struct multiboot_header_tag *) ((grub_uint32_t *) tag + ALIGN_UP (tag->size, MULTIBOOT_TAG_ALIGN) / 4)) + tag = (struct multiboot_header_tag *) ((char *) tag + ALIGN_UP (tag->size, MULTIBOOT_TAG_ALIGN))) switch (tag->type) { case MULTIBOOT_HEADER_TAG_INFORMATION_REQUEST: -- 2.26.2