]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs: refactor xfs_btree_diff_two_ptrs() to take advantage of cmp_int()
authorFedor Pchelkin <pchelkin@ispras.ru>
Mon, 6 Oct 2025 12:40:17 +0000 (14:40 +0200)
committerAndrey Albershteyn <aalbersh@kernel.org>
Mon, 13 Oct 2025 09:53:39 +0000 (11:53 +0200)
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 <pchelkin@ispras.ru>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
Signed-off-by: Andrey Albershteyn <aalbersh@kernel.org>
Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>
libxfs/xfs_btree.c
libxfs/xfs_btree.h

index facc35401f5d2e5af6d18917e9748d06eda64290..8576611994f4267c269fb707d2e285d3c0adc1ca 100644 (file)
@@ -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 {
index 1bf20d509ac99fd609c24f2a388eff679e034db2..60e78572e72555377bc7ab8ca2f30fb1624a20c5 100644 (file)
@@ -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);