]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
xfs: refactor xfs_btree_diff_two_ptrs() to take advantage of cmp_int()
authorFedor Pchelkin <pchelkin@ispras.ru>
Wed, 2 Jul 2025 09:39:33 +0000 (12:39 +0300)
committerCarlos Maiolino <cem@kernel.org>
Thu, 24 Jul 2025 15:30:13 +0000 (17:30 +0200)
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>
fs/xfs/libxfs/xfs_btree.c
fs/xfs/libxfs/xfs_btree.h
fs/xfs/scrub/btree.c

index d3591728998e387a6f7930106bc209d131a48940..a61211d253f1ca9f91e810da38ba9197a12082f4 100644 (file)
@@ -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 {
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);
index fe678a0438bc5c90c04e19878cf979ff708de69b..cd6f0ff382a7c8d85a8375a13a73920697da53ed 100644 (file)
@@ -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);