lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Fri, 23 Oct 2020 17:07:33 -0600
From:   Andreas Dilger <adilger@...ger.ca>
To:     Chunguang Xu <brookxu.cn@...il.com>
Cc:     Ted Tso <tytso@....edu>,
        Ext4 Developers List <linux-ext4@...r.kernel.org>
Subject: Re: [PATCH 3/8] ext4: simplify the code of mb_find_order_for_block

On Oct 21, 2020, at 3:15 AM, Chunguang Xu <brookxu.cn@...il.com> wrote:
> 
> From: Chunguang Xu <brookxu@...cent.com>
> 
> The code of mb_find_order_for_block is a bit obscure, but we can
> simplify it with mb_find_buddy(), make the code more concise.
> 
> Signed-off-by: Chunguang Xu <brookxu@...cent.com>

Removing lines is always good.

Reviewed-by: Andreas Dilger <adilger@...ger.ca>

> ---
> fs/ext4/mballoc.c | 10 +++-------
> 1 file changed, 3 insertions(+), 7 deletions(-)
> 
> static int mb_find_order_for_block(struct ext4_buddy *e4b, int block)
> {
> -	int order = 1;
> -	int bb_incr = 1 << (e4b->bd_blkbits - 1);
> +	int order = 1, max;
> 	void *bb;
> 
> 	BUG_ON(e4b->bd_bitmap == e4b->bd_buddy);
> 	BUG_ON(block >= (1 << (e4b->bd_blkbits + 3)));
> 
> -	bb = e4b->bd_buddy;
> 	while (order <= e4b->bd_blkbits + 1) {
> -		block = block >> 1;
> -		if (!mb_test_bit(block, bb)) {
> +		bb = mb_find_buddy(e4b, order, &max);
> +		if (!mb_test_bit(block >> order, bb)) {
> 			/* this block is part of buddy of order 'order' */
> 			return order;
> 		}
> -		bb += bb_incr;
> -		bb_incr >>= 1;
> 		order++;
> 	}

(style) this while loop is actually a for loop:

	for (order = 1; order <= e4b->bd_blkbits + 1; order++) {

Cheers, Andreas






Download attachment "signature.asc" of type "application/pgp-signature" (874 bytes)

Powered by blists - more mailing lists