[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] bufio: round up block size to power of 2
From: |
Michael Chang |
Subject: |
[PATCH] bufio: round up block size to power of 2 |
Date: |
Fri, 20 Apr 2018 15:21:30 +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>
---
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
- [PATCH] bufio: round up block size to power of 2,
Michael Chang <=