diff options
| author | Fedor Pchelkin <[email protected]> | 2025-07-02 09:39:30 +0000 |
|---|---|---|
| committer | Carlos Maiolino <[email protected]> | 2025-07-24 15:30:13 +0000 |
| commit | 3b583adf55c649d5ba37bcd1ca87644b0bc10b86 (patch) | |
| tree | 9cd595ba157367cabd7e3984b2e5cdb134aed23e /fs/xfs/libxfs/xfs_rtrmap_btree.c | |
| parent | xfs: rename key_diff routines (diff) | |
| download | kernel-3b583adf55c649d5ba37bcd1ca87644b0bc10b86.tar.gz kernel-3b583adf55c649d5ba37bcd1ca87644b0bc10b86.zip | |
xfs: refactor cmp_two_keys 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_two_keys routines from int64_t to int and make the
interface a bit clearer.
Found by Linux Verification Center (linuxtesting.org).
Suggested-by: Darrick J. Wong <[email protected]>
Signed-off-by: Fedor Pchelkin <[email protected]>
Reviewed-by: Darrick J. Wong <[email protected]>
Signed-off-by: Carlos Maiolino <[email protected]>
Diffstat (limited to 'fs/xfs/libxfs/xfs_rtrmap_btree.c')
| -rw-r--r-- | fs/xfs/libxfs/xfs_rtrmap_btree.c | 29 |
1 files changed, 12 insertions, 17 deletions
diff --git a/fs/xfs/libxfs/xfs_rtrmap_btree.c b/fs/xfs/libxfs/xfs_rtrmap_btree.c index b48336086ca7..231a189ea2fe 100644 --- a/fs/xfs/libxfs/xfs_rtrmap_btree.c +++ b/fs/xfs/libxfs/xfs_rtrmap_btree.c @@ -215,7 +215,7 @@ xfs_rtrmapbt_cmp_key_with_cur( return 0; } -STATIC int64_t +STATIC int xfs_rtrmapbt_cmp_two_keys( struct xfs_btree_cur *cur, const union xfs_btree_key *k1, @@ -224,36 +224,31 @@ xfs_rtrmapbt_cmp_two_keys( { const struct xfs_rmap_key *kp1 = &k1->rmap; const struct xfs_rmap_key *kp2 = &k2->rmap; - int64_t d; - __u64 x, y; + int d; /* Doesn't make sense to mask off the physical space part */ ASSERT(!mask || mask->rmap.rm_startblock); - d = (int64_t)be32_to_cpu(kp1->rm_startblock) - - be32_to_cpu(kp2->rm_startblock); + d = cmp_int(be32_to_cpu(kp1->rm_startblock), + be32_to_cpu(kp2->rm_startblock)); if (d) return d; if (!mask || mask->rmap.rm_owner) { - x = be64_to_cpu(kp1->rm_owner); - y = be64_to_cpu(kp2->rm_owner); - if (x > y) - return 1; - else if (y > x) - return -1; + d = cmp_int(be64_to_cpu(kp1->rm_owner), + be64_to_cpu(kp2->rm_owner)); + if (d) + return d; } if (!mask || mask->rmap.rm_offset) { /* Doesn't make sense to allow offset but not owner */ ASSERT(!mask || mask->rmap.rm_owner); - x = offset_keymask(be64_to_cpu(kp1->rm_offset)); - y = offset_keymask(be64_to_cpu(kp2->rm_offset)); - if (x > y) - return 1; - else if (y > x) - return -1; + d = cmp_int(offset_keymask(be64_to_cpu(kp1->rm_offset)), + offset_keymask(be64_to_cpu(kp2->rm_offset))); + if (d) + return d; } return 0; |
