Re: [PATCH v2] bufio: round up block size to power of 2

2018-04-24 Thread 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 
>
> 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

___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH v2] bufio: round up block size to power of 2

2018-04-24 Thread Michael Chang
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 

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


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel