Received: from list by lists.gnu.org with archive (Exim 4.71) id 1fAbyI-00069S-79 for mharc-grub-devel@gnu.org; Mon, 23 Apr 2018 09:57:34 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53377) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fAbyF-00067h-HU for grub-devel@gnu.org; Mon, 23 Apr 2018 09:57:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fAbyA-0007OY-NH for grub-devel@gnu.org; Mon, 23 Apr 2018 09:57:31 -0400 Received: from boksu.net-space.pl ([185.15.1.105]:35738) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_3DES_EDE_CBC_SHA1:24) (Exim 4.71) (envelope-from ) id 1fAbyA-0007Mx-By for grub-devel@gnu.org; Mon, 23 Apr 2018 09:57:26 -0400 Received: (from localhost user: 'dkiper' uid#4000 fake: STDIN (dkiper@boksu.net-space.pl)) by router-fw-old.local.net-space.pl id S1837315AbeDWN5W (ORCPT ); Mon, 23 Apr 2018 15:57:22 +0200 Date: Mon, 23 Apr 2018 15:57:22 +0200 From: Daniel Kiper To: mchang@suse.com, Daniel Kiper Cc: grub-devel@gnu.org Subject: Re: [PATCH] bufio: round up block size to power of 2 Message-ID: <20180423135722.GC4061@router-fw-old.local.net-space.pl> References: <20180420072130.qm3lyhwwtc46znph@mazu> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180420072130.qm3lyhwwtc46znph@mazu> User-Agent: Mutt/1.3.28i X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 185.15.1.105 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: Mon, 23 Apr 2018 13:57:32 -0000 On Fri, Apr 20, 2018 at 03:21:30PM +0800, Michael Chang wrote: > 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 */ May I ask you to say why here? > + if (size & (size - 1)) > + { > + int round_up; > + for (round_up = 1; round_up < size; round_up <<= 1); > + size = round_up; > + } Please use this (stolen from linux/drivers/md/raid5.c): while (size & (size - 1)) size = (size | (size - 1)) + 1; Daniel