Re: [PATCH] btrfs: cleanup for open-coded alignment

Zach Brown
Tue, 26 Feb 2013 18:53:20 -0000

> Sometimes these open-coded alignment is not so easy to understand for
> newbie like me.

Thanks, this is a nice change.

You might have mentioned in the commit message that some of the changes
aren''t *strictly* equivalent but that they''re still safe.

> -		iosize = (iosize + blocksize - 1) & ~((u64)blocksize - 1);
> +		iosize = ALIGN(iosize, blocksize);

This is equivalent to

> +		iosize = (iosize + blocksize - 1) & ~((size_t)blocksize - 1);

Which is fine.  That u64 was overkill.  The manual casts only need to
make sure that the mask is as wide as the input value to avoid losing
bits and the macro now guarantees that.

> -	num_bytes = (end - start + blocksize) & ~(blocksize - 1);
> +	num_bytes = ALIGN(end - start + 1, blocksize);

Nice catch.

Reviewed-by: Zach Brown <zab@redhat.com>

- z