grub-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


From: Daniel Kiper
Subject: Re: [PATCH] bufio: round up block size to power of 2
Date: Mon, 23 Apr 2018 15:57:22 +0200
User-agent: Mutt/1.3.28i

On Fri, Apr 20, 2018 at 03:21:30PM +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 <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 */

May I ask you to say why here?

> +  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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]