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

xfs: refactor cmp_key_with_cur routines to take advantage of cmp_int()



The net value of these functions is to determine the result of a
three-way-comparison between operands of the same type.

Simplify the code using cmp_int() to eliminate potential errors with
opencoded casts and subtractions. This also means we can change the return
value type of cmp_key_with_cur routines from int64_t to int and make the
interface a bit clearer.

Found by Linux Verification Center (linuxtesting.org).

Suggested-by: default avatarDarrick J. Wong <djwong@kernel.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 3b583adf
Loading
Loading
Loading
Loading
+6 −9
Original line number Diff line number Diff line
@@ -186,7 +186,7 @@ xfs_allocbt_init_ptr_from_cur(
		ptr->s = agf->agf_cnt_root;
}

STATIC int64_t
STATIC int
xfs_bnobt_cmp_key_with_cur(
	struct xfs_btree_cur		*cur,
	const union xfs_btree_key	*key)
@@ -194,23 +194,20 @@ xfs_bnobt_cmp_key_with_cur(
	struct xfs_alloc_rec_incore	*rec = &cur->bc_rec.a;
	const struct xfs_alloc_rec	*kp = &key->alloc;

	return (int64_t)be32_to_cpu(kp->ar_startblock) - rec->ar_startblock;
	return cmp_int(be32_to_cpu(kp->ar_startblock),
		       rec->ar_startblock);
}

STATIC int64_t
STATIC int
xfs_cntbt_cmp_key_with_cur(
	struct xfs_btree_cur		*cur,
	const union xfs_btree_key	*key)
{
	struct xfs_alloc_rec_incore	*rec = &cur->bc_rec.a;
	const struct xfs_alloc_rec	*kp = &key->alloc;
	int64_t				diff;

	diff = (int64_t)be32_to_cpu(kp->ar_blockcount) - rec->ar_blockcount;
	if (diff)
		return diff;

	return (int64_t)be32_to_cpu(kp->ar_startblock) - rec->ar_startblock;
	return cmp_int(be32_to_cpu(kp->ar_blockcount), rec->ar_blockcount) ?:
	       cmp_int(be32_to_cpu(kp->ar_startblock), rec->ar_startblock);
}

STATIC int
+3 −3
Original line number Diff line number Diff line
@@ -369,13 +369,13 @@ xfs_bmbt_init_rec_from_cur(
	xfs_bmbt_disk_set_all(&rec->bmbt, &cur->bc_rec.b);
}

STATIC int64_t
STATIC int
xfs_bmbt_cmp_key_with_cur(
	struct xfs_btree_cur		*cur,
	const union xfs_btree_key	*key)
{
	return (int64_t)be64_to_cpu(key->bmbt.br_startoff) -
				      cur->bc_rec.b.br_startoff;
	return cmp_int(be64_to_cpu(key->bmbt.br_startoff),
		       cur->bc_rec.b.br_startoff);
}

STATIC int
+1 −1
Original line number Diff line number Diff line
@@ -175,7 +175,7 @@ struct xfs_btree_ops {
	 * Compare key value and cursor value -- positive if key > cur,
	 * negative if key < cur, and zero if equal.
	 */
	int64_t (*cmp_key_with_cur)(struct xfs_btree_cur *cur,
	int	(*cmp_key_with_cur)(struct xfs_btree_cur *cur,
				    const union xfs_btree_key *key);

	/*
+3 −3
Original line number Diff line number Diff line
@@ -265,13 +265,13 @@ xfs_finobt_init_ptr_from_cur(
	ptr->s = agi->agi_free_root;
}

STATIC int64_t
STATIC int
xfs_inobt_cmp_key_with_cur(
	struct xfs_btree_cur		*cur,
	const union xfs_btree_key	*key)
{
	return (int64_t)be32_to_cpu(key->inobt.ir_startino) -
			  cur->bc_rec.i.ir_startino;
	return cmp_int(be32_to_cpu(key->inobt.ir_startino),
		       cur->bc_rec.i.ir_startino);
}

STATIC int
+2 −2
Original line number Diff line number Diff line
@@ -174,7 +174,7 @@ xfs_refcountbt_init_ptr_from_cur(
	ptr->s = agf->agf_refcount_root;
}

STATIC int64_t
STATIC int
xfs_refcountbt_cmp_key_with_cur(
	struct xfs_btree_cur		*cur,
	const union xfs_btree_key	*key)
@@ -185,7 +185,7 @@ xfs_refcountbt_cmp_key_with_cur(

	start = xfs_refcount_encode_startblock(irec->rc_startblock,
			irec->rc_domain);
	return (int64_t)be32_to_cpu(kp->rc_startblock) - start;
	return cmp_int(be32_to_cpu(kp->rc_startblock), start);
}

STATIC int
Loading