Received: from list by lists.gnu.org with archive (Exim 4.71) id 1f9QMd-000556-64 for mharc-grub-devel@gnu.org; Fri, 20 Apr 2018 03:21:47 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58633) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f9QMb-00053E-0Z for grub-devel@gnu.org; Fri, 20 Apr 2018 03:21:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f9QMX-0001Uo-Ns for grub-devel@gnu.org; Fri, 20 Apr 2018 03:21:45 -0400 Received: from prv3-mh.provo.novell.com ([137.65.250.26]:47011) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1f9QMX-00019y-He for grub-devel@gnu.org; Fri, 20 Apr 2018 03:21:41 -0400 Received: from mazu (prv-ext-foundry1int.gns.novell.com [137.65.251.240]) by prv3-mh.provo.novell.com with ESMTP (TLS encrypted); Fri, 20 Apr 2018 01:21:34 -0600 Date: Fri, 20 Apr 2018 15:21:30 +0800 From: Michael Chang To: grub-devel@gnu.org, Daniel Kiper Subject: [PATCH] bufio: round up block size to power of 2 Message-ID: <20180420072130.qm3lyhwwtc46znph@mazu> Mail-Followup-To: grub-devel@gnu.org, Daniel Kiper MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: NeoMutt/20170421 (1.8.2) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 137.65.250.26 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 20 Apr 2018 07:21:45 -0000 Rounding up the bufio->block_size to meet power of 2 to facilitate next_buf calcuation in grub_bufio_read. Signed-off-by: Michael Chang --- grub-core/io/bufio.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/grub-core/io/bufio.c b/grub-core/io/bufio.c index 22438277d..4d66b65a3 100644 --- a/grub-core/io/bufio.c +++ b/grub-core/io/bufio.c @@ -61,6 +61,14 @@ grub_bufio_open (grub_file_t io, int size) size = ((io->size > GRUB_BUFIO_MAX_SIZE) ? GRUB_BUFIO_MAX_SIZE : io->size); + /* round up size to power of 2 */ + if (size & (size - 1)) + { + int round_up; + for (round_up = 1; round_up < size; round_up <<= 1); + size = round_up; + } + bufio = grub_zalloc (sizeof (struct grub_bufio) + size); if (! bufio) { -- 2.13.6