[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2] bufio: round up block size to power of 2
From: |
Michael Chang |
Subject: |
[PATCH v2] bufio: round up block size to power of 2 |
Date: |
Tue, 24 Apr 2018 14:13:04 +0800 |
User-agent: |
NeoMutt/20170421 (1.8.2) |
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 <address@hidden>
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
- [PATCH v2] bufio: round up block size to power of 2,
Michael Chang <=