bufio: Round up block size to power of 2
Rounding up the bufio->block_size to meet power of 2 to facilitate next_buf calculation in grub_bufio_read(). Signed-off-by: Michael Chang <mchang@suse.com> Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
This commit is contained in:
parent
d86ee9b3e3
commit
a09de36b3c
1 changed files with 7 additions and 0 deletions
|
@ -61,6 +61,13 @@ grub_bufio_open (grub_file_t io, int size)
|
||||||
size = ((io->size > GRUB_BUFIO_MAX_SIZE) ? GRUB_BUFIO_MAX_SIZE :
|
size = ((io->size > GRUB_BUFIO_MAX_SIZE) ? GRUB_BUFIO_MAX_SIZE :
|
||||||
io->size);
|
io->size);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Round up size to power of 2 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);
|
bufio = grub_zalloc (sizeof (struct grub_bufio) + size);
|
||||||
if (! bufio)
|
if (! bufio)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue