From: Fedor Pchelkin Date: Mon, 6 Oct 2025 12:40:17 +0000 (+0200) Subject: xfs: refactor xfs_btree_diff_two_ptrs() to take advantage of cmp_int() X-Git-Tag: v6.17.0~7 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ff1a5239a94f7ad3db4ebd9897c4d1e83292feae;p=thirdparty%2Fxfsprogs-dev.git xfs: refactor xfs_btree_diff_two_ptrs() to take advantage of cmp_int() Source kernel commit: ce6cce46aff79423f47680ee65e8f12191a50605 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: Fedor Pchelkin Reviewed-by: Darrick J. Wong Signed-off-by: Carlos Maiolino Signed-off-by: Andrey Albershteyn Reviewed-by: "Darrick J. Wong" --- diff --git a/libxfs/xfs_btree.c b/libxfs/xfs_btree.c index facc3540..85766119 100644 --- a/libxfs/xfs_btree.c +++ b/libxfs/xfs_btree.c @@ -5350,15 +5350,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 { diff --git a/libxfs/xfs_btree.h b/libxfs/xfs_btree.h index 1bf20d50..60e78572 100644 --- a/libxfs/xfs_btree.h +++ b/libxfs/xfs_btree.h @@ -519,9 +519,9 @@ 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, - const union xfs_btree_ptr *a, - const union xfs_btree_ptr *b); +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, struct xfs_btree_block *block, union xfs_btree_ptr *ptr, int lr);