All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] bufio: round up block size to power of 2
@ 2018-04-24  6:13 Michael Chang
  2018-04-24  9:39 ` Daniel Kiper
  0 siblings, 1 reply; 2+ messages in thread
From: Michael Chang @ 2018-04-24  6:13 UTC (permalink / raw)
  To: grub-devel, Daniel Kiper

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 <mchang@suse.com>

v2:
  - Use a more terse approach to round up size suggested by Daniel
  - Added comment to explain why to have the size rounded
---
 grub-core/io/bufio.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/grub-core/io/bufio.c b/grub-core/io/bufio.c
index 22438277d..75adaa135 100644
--- a/grub-core/io/bufio.c
+++ b/grub-core/io/bufio.c
@@ -61,6 +61,11 @@ 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 to which the binary math to calculate next_buf
+     in grub_bufio_read requires. */
+  while (size & (size - 1))
+    size = (size | (size - 1)) + 1;
+
   bufio = grub_zalloc (sizeof (struct grub_bufio) + size);
   if (! bufio)
     {
-- 
2.13.6



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] bufio: round up block size to power of 2
  2018-04-24  6:13 [PATCH v2] bufio: round up block size to power of 2 Michael Chang
@ 2018-04-24  9:39 ` Daniel Kiper
  0 siblings, 0 replies; 2+ messages in thread
From: Daniel Kiper @ 2018-04-24  9:39 UTC (permalink / raw)
  To: Michael Chang; +Cc: grub-devel, Daniel Kiper

On Tue, Apr 24, 2018 at 02:13:04PM +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 <mchang@suse.com>
>
> v2:

Next time please put "---" before "v2:" just after SOB.
This way git am will not pull v2 changes description into
commit message. Otherwise it looks good to me. If there
are no objections I will commit this in a week or so.

Daniel


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-04-24  9:39 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-24  6:13 [PATCH v2] bufio: round up block size to power of 2 Michael Chang
2018-04-24  9:39 ` Daniel Kiper

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.