Commit ce6cce46 authored by Fedor Pchelkin's avatar Fedor Pchelkin Committed by Carlos Maiolino
Browse files

xfs: refactor xfs_btree_diff_two_ptrs() to take advantage of cmp_int()



Use cmp_int() to yield the result of a three-way-comparison instead of
performing subtractions with extra casts. Thus also rename the function
to make its name clearer in purpose.

Found by Linux Verification Center (linuxtesting.org).

Signed-off-by: default avatarFedor Pchelkin <pchelkin@ispras.ru>
Reviewed-by: default avatarDarrick J. Wong <djwong@kernel.org>
Signed-off-by: default avatarCarlos Maiolino <cem@kernel.org>
parent 2717eb35
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -5353,15 +5353,15 @@ xfs_btree_count_blocks(
}

/* Compare two btree pointers. */
int64_t
xfs_btree_diff_two_ptrs(
int
xfs_btree_cmp_two_ptrs(
	struct xfs_btree_cur		*cur,
	const union xfs_btree_ptr	*a,
	const union xfs_btree_ptr	*b)
{
	if (cur->bc_ops->ptr_len == XFS_BTREE_LONG_PTR_LEN)
		return (int64_t)be64_to_cpu(a->l) - be64_to_cpu(b->l);
	return (int64_t)be32_to_cpu(a->s) - be32_to_cpu(b->s);
		return cmp_int(be64_to_cpu(a->l), be64_to_cpu(b->l));
	return cmp_int(be32_to_cpu(a->s), be32_to_cpu(b->s));
}

struct xfs_btree_has_records {
+3 −3
Original line number Diff line number Diff line
@@ -519,7 +519,7 @@ struct xfs_btree_block *xfs_btree_get_block(struct xfs_btree_cur *cur,
		int level, struct xfs_buf **bpp);
bool xfs_btree_ptr_is_null(struct xfs_btree_cur *cur,
		const union xfs_btree_ptr *ptr);
int64_t xfs_btree_diff_two_ptrs(struct xfs_btree_cur *cur,
int xfs_btree_cmp_two_ptrs(struct xfs_btree_cur *cur,
			   const union xfs_btree_ptr *a,
			   const union xfs_btree_ptr *b);
void xfs_btree_get_sibling(struct xfs_btree_cur *cur,
+1 −1
Original line number Diff line number Diff line
@@ -306,7 +306,7 @@ xchk_btree_block_check_sibling(
	if (pbp)
		xchk_buffer_recheck(bs->sc, pbp);

	if (xfs_btree_diff_two_ptrs(cur, pp, sibling))
	if (xfs_btree_cmp_two_ptrs(cur, pp, sibling))
		xchk_btree_set_corrupt(bs->sc, cur, level);
out:
	xfs_btree_del_cursor(ncur, XFS_BTREE_ERROR);