bufio: round up block size to power of 2
PATCH 1/1 bufio: round up block size to power of 2
Rounding up the bufio->block_size to meet power of 2 to facilitate next_buf calcuation in grub_bufio_read.
--- grub-core/io/bufio.c | 8 ++++++++ 1 file changed, 8 insertions(+)
grub-core/io/bufio.c +8 -0
@@ -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) {
Signature · 1 line
2.13.6
Quoted 13 lines · Michael Chang
Rounding up the
bufio->block_sizeto meet power of 2 to facilitatenext_bufcalcuation ingrub_bufio_read.Signed-off-by Michael Chang <[email protected]>--- grub-core/io/bufio.c | 8 ++++++++ 1 file changed, 8 insertions(+)grub-core/io/bufio.c +0
-0
grub-core/io/bufio.c grub_bufio_open (grub_file_t io, int size) · line 64
Quoted 4 lines
grub-core/io/bufio.c +1
-0@@ -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?
grub-core/io/bufio.c grub_bufio_open (grub_file_t io, int size) · line 70
Quoted 6 lines
grub-core/io/bufio.c +6
-0+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
Quoted 17 lines · Daniel Kiper
Quoted 16 lines · Michael Chang
Rounding up the
bufio->block_sizeto meet power of 2 to facilitatenext_bufcalcuation ingrub_bufio_read.Signed-off-by Michael Chang <[email protected]>--- grub-core/io/bufio.c | 8 ++++++++ 1 file changed, 8 insertions(+)grub-core/io/bufio.c +0
-0@@ -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);
Quoted 3 lines
grub-core/io/bufio.c grub_bufio_open (grub_file_t io, int size) · line 64
Quoted 1 line
grub-core/io/bufio.c +1
-0+/* round up size to power of 2 */ May I ask you to say why here?
OK.
Quoted 11 lines
grub-core/io/bufio.c grub_bufio_open (grub_file_t io, int size) · line 70
Quoted 7 lines
grub-core/io/bufio.c +6
-0+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;
Cool. They will be added in upcoming V2 patch.
Thanks,
Michael
Quoted 2 lines
Daniel